Submission #881049

#TimeUsernameProblemLanguageResultExecution timeMemory
881049epicci23Povjerenstvo (COI22_povjerenstvo)C++17
21 / 100
317 ms64988 KiB
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n" 
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 * SIMPLIFY THE PROBLEM
 * READ THE STATEMENT CAREFULLY
  !!! if there is an specified/interesting smth(i.e. constraint) in the statement,
  then you must be careful about that   
*/

const int N = 5e5 + 5;
vector<int> v[N],cur[2],vis(N,0);

void dfs(int c,int col){
  cur[col].pb(c);
  vis[c]=1;
  for(int x:v[c]){
    if(vis[x]) continue;
    dfs(x,!col);
  }  
}

void solve(){
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
   
    vector<int> ans;

    for(int i=1;i<=n;i++){
      if(vis[i]) continue;
      cur[0].clear();cur[1].clear();
      dfs(i,0);
      if(sz(cur[0])<sz(cur[1])) swap(cur[0],cur[1]);
      for(int x:cur[0]) ans.pb(x); 
    }

    cout << sz(ans) << endl;
    for(int x:ans) cout << x << " ";
    cout << endl;
}

int32_t main(){

  cin.tie(0); ios::sync_with_stdio(0);
  
  int t=1;//cin >> t;
  while(t--) solve();

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...