My first problem!!
Solve it!!
https://codeforces.net/contestInvitation/4bf6a8100a2d41dbc81a8636dadfef2ca6287eb9
If there multiple answers, you checker count only answer with minimum index. Question itself is good.
Thanks for your feedback, the text has changed.
Auto comment: topic has been translated by Azuken (original revision, translated revision, compare)
samples pass in custom invocation but still runtime error on samples when submitting?
// Have mercy upon us, O arav, our savior #include<bits/stdc++.h> #ifndef ONLINE_JUDGE #include "anshul.cpp" extern void sublime(); #else #define see(...) 42 #endif #define int long long using namespace std; void dfs(vector<vector<int>>& adj,vector<bool>& vis, vector<int>& component, int CurrentComponent, int CurrentNode) { if(vis[CurrentNode]) return; vis[CurrentNode] = true; component[CurrentNode] = CurrentComponent; for(auto neighbour : adj[CurrentNode]) dfs(adj,vis,component,CurrentComponent,neighbour); } void solve() { int n,m; cin>>n; m = n-1; vector<vector<int>> adj(n); for(int i=0;i<m;i++) { int x,y; cin>>x>>y; x--;y--; adj[x].push_back(y); adj[y].push_back(x); } vector<int> ans; vector<bool> vis(n,false); vector<int> component(n); int CurrentComponent = 1; for(int node=0;node<n;node++) { if(!vis[node]) { dfs(adj,vis,component,CurrentComponent,node); CurrentComponent++; } } int mx_cmp = 1; int mx_size = 1; map<int,int> size; for(int i=0;i<n;i++) { size[component[i]]++; if(size[component[i]] >= mx_size) { mx_size = size[component[i]]; mx_cmp = component[i]; } } for(int i=0;i<n;i++) { if(component[i] == mx_cmp) { cout<<i+1<<endl; return; } } } signed main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE sublime(); #endif solve(); return 0; }
UPD: my bad, forgot to add
freopen("babochkain.txt", "r", stdin); freopen("babochkaout.txt", "w", stdout);
If there multiple answers, you checker count only answer with minimum index. Question itself is good.
Thanks for your feedback, the text has changed.
Auto comment: topic has been translated by Azuken (original revision, translated revision, compare)
samples pass in custom invocation but still runtime error on samples when submitting?
UPD: my bad, forgot to add