Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Destroy It!
#include <bits/stdc++.h> using namespace std; vector<int> ans; vector<int> ans2; vector<int> v[200005]; int vis[200005]; void DFS(int node,int check) { if(check==1) ans.push_back(node); else ans2.push_back(node); vis[node]=1; for(int i=0;i<v[node].size();i++) { if(vis[v[node][i]]==0) { DFS(v[node][i],-1*check); } } } int main() { int t; scanf("%d",&t); while(t--) { int n,m,x,y; scanf("%d%d",&n,&m); for(int i=0;i<=n;i++) v[i].clear(),vis[i]=0; for(int i=0;i<m;i++) { scanf("%d%d",&x,&y); v[x].push_back(y); v[y].push_back(x); } ans.clear(); ans2.clear(); DFS(1,1); if(ans.size()<=n/2) { printf("%d\n",ans.size()); for(int i=0;i<ans.size();i++) printf("%d ",ans[i]); printf("\n"); } else { if(ans2.size()<=n/2) { printf("%d\n",ans2.size()); for(int i=0;i<ans2.size();i++) printf("%d ",ans2[i]); printf("\n"); } } } }
run
|
edit
|
history
|
help
0
compute power to a number manually, and by using function.
Preference List
StackQuiz
Web Browser History - LIST
kadane's algorithm
Value equal to index value
test
override
Constructor.cpp
NumberToWords