Submission #881047

# Submission time Handle Problem Language Result Execution time Memory
881047 2023-11-30T12:08:53 Z epicci23 Povjerenstvo (COI22_povjerenstvo) C++17
0 / 100
47 ms 28576 KB
#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 = 2e5 + 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 time Memory Grader output
1 Runtime error 47 ms 28576 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 46 ms 28496 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Correct 3 ms 7004 KB Output is correct
3 Correct 3 ms 7000 KB Output is correct
4 Correct 3 ms 7000 KB Output is correct
5 Correct 3 ms 7004 KB Output is correct
6 Correct 3 ms 7000 KB Output is correct
7 Correct 3 ms 7000 KB Output is correct
8 Correct 3 ms 6996 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 4 ms 7000 KB Output is correct
13 Correct 3 ms 6996 KB Output is correct
14 Incorrect 2 ms 6748 KB There must not be two people within the committee such that one person dislikes the other.
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 47 ms 28576 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -