# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
959989 | 2024-04-09T11:53:53 Z | pcc | Povjerenstvo (COI22_povjerenstvo) | C++17 | 101 ms | 33748 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<int> paths[mxn]; int deg[mxn]; queue<int> q; int ans[mxn]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>M; memset(ans,-1,sizeof(ans)); for(int i = 1;i<=M;i++){ int a,b; cin>>a>>b; deg[a]++; paths[b].push_back(a); } for(int i = 1;i<=N;i++)if(!deg[i])q.push(i); while(!q.empty()){ auto now = q.front(); q.pop(); if(ans[now] == -1)ans[now] = 1; for(auto nxt:paths[now]){ deg[nxt]--; if(!deg[nxt])q.push(nxt); if(ans[now] == 1){ if(ans[nxt] == -1)ans[nxt] = 0; else{ cout<<-1; return 0; } } } } vector<int> v; for(int i = 1;i<=N;i++){ if(ans[i] == 1)v.push_back(i); } cout<<v.size()<<'\n'; for(auto &i:v)cout<<i<<' ';cout<<'\n'; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 95 ms | 33748 KB | Output is correct |
2 | Correct | 101 ms | 33480 KB | Output is correct |
3 | Correct | 4 ms | 15960 KB | Output is correct |
4 | Correct | 47 ms | 23120 KB | Output is correct |
5 | Correct | 69 ms | 27600 KB | Output is correct |
6 | Incorrect | 67 ms | 32332 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 96 ms | 33656 KB | Output is correct |
2 | Incorrect | 69 ms | 32592 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 16220 KB | Output is correct |
2 | Incorrect | 4 ms | 16220 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 95 ms | 33748 KB | Output is correct |
2 | Correct | 101 ms | 33480 KB | Output is correct |
3 | Correct | 4 ms | 15960 KB | Output is correct |
4 | Correct | 47 ms | 23120 KB | Output is correct |
5 | Correct | 69 ms | 27600 KB | Output is correct |
6 | Incorrect | 67 ms | 32332 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |