Submission #959998

# Submission time Handle Problem Language Result Execution time Memory
959998 2024-04-09T12:16:50 Z pcc Povjerenstvo (COI22_povjerenstvo) C++17
0 / 100
242 ms 50632 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")

#define pii pair<int,int>
#define fs first
#define sc second
#define ll long long

const int mxn = 5e5+10;

int N,M;
vector<pii> paths[mxn];
int deg[mxn];
bitset<mxn> done;
vector<int> v;
vector<int> cc;
int col[mxn];

void dfs(int now,int c){
	cc.push_back(now);
	col[now] = c;
	for(auto [nxt,___]:paths[now]){
		if(!col[nxt])dfs(nxt,-c);
	}
	return;
}

bool choose(int c){
	for(auto &i:cc){
		if(col[i] == c)continue;
		bool flag = false;
		for(auto [nxt,w]:paths[i]){
			if(w == 1)flag = true;
		}
		if(!flag)return false;
	}
	return true;
}

void calc(int now){
	cc.clear();
	dfs(now,1);
	if(choose(1)){
		for(auto &i:cc)if(col[i] == 1)v.push_back(i);
	}
	else if(choose(-1)){
		for(auto &i:cc)if(col[i] == -1)v.push_back(i);
	}
	else{
		cout<<-1;
		exit(0);
	}
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	for(int i = 1;i<=M;i++){
		int a,b;
		cin>>a>>b;
		paths[a].push_back(pii(b,1));
		paths[b].push_back(pii(a,-1));
	}
	for(int i = 1;i<=N;i++){
		if(!col[i])calc(i);
	}
	cout<<v.size()<<'\n';
	for(auto &i:v)cout<<i<<' ';cout<<'\n';
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:72:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   72 |  for(auto &i:v)cout<<i<<' ';cout<<'\n';
      |  ^~~
Main.cpp:72:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   72 |  for(auto &i:v)cout<<i<<' ';cout<<'\n';
      |                             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 124 ms 50632 KB Output is correct
2 Correct 118 ms 35232 KB Output is correct
3 Correct 3 ms 15964 KB Output is correct
4 Correct 35 ms 21204 KB Output is correct
5 Correct 72 ms 34464 KB Output is correct
6 Correct 118 ms 42912 KB Output is correct
7 Correct 82 ms 39352 KB Output is correct
8 Correct 102 ms 42676 KB Output is correct
9 Correct 242 ms 40128 KB Output is correct
10 Incorrect 194 ms 35036 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 120 ms 50484 KB Output is correct
2 Correct 107 ms 43512 KB Output is correct
3 Correct 77 ms 38328 KB Output is correct
4 Incorrect 187 ms 36044 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 16216 KB Output is correct
2 Correct 6 ms 16220 KB Output is correct
3 Correct 4 ms 16068 KB Output is correct
4 Incorrect 6 ms 16216 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 50632 KB Output is correct
2 Correct 118 ms 35232 KB Output is correct
3 Correct 3 ms 15964 KB Output is correct
4 Correct 35 ms 21204 KB Output is correct
5 Correct 72 ms 34464 KB Output is correct
6 Correct 118 ms 42912 KB Output is correct
7 Correct 82 ms 39352 KB Output is correct
8 Correct 102 ms 42676 KB Output is correct
9 Correct 242 ms 40128 KB Output is correct
10 Incorrect 194 ms 35036 KB Output isn't correct
11 Halted 0 ms 0 KB -