답안 #960241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960241 2024-04-10T01:32:03 Z Darren0724 Povjerenstvo (COI22_povjerenstvo) C++17
0 / 100
46 ms 28628 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
//#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
int n,m;
vector<int> vis(N,-1),out(N,0);
vector<int> adj[N];
int32_t main() {
    LCBorz;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        out[a]++;
        adj[b].push_back(a);
    }
    vector<int> ans1(N,-1);
    queue<int> q;
    for(int i=1;i<=n;i++){
        if(out[i]==0){
            ans1[i]=1;
            q.push(i);
        }
    }
    while(q.size()){
        int p=q.front();
        q.pop();
        ans1[p]=1;
        for(int j:adj[p]){
            if(ans1[j]==1){
                cout<<-1<<endl;
                return 0;
            }
            if(ans1[j]==-1){
                for(int j1:adj[j]){
                    out[j1]--;
                    if(out[j1]==0){
                        q.push(j1);
                    }
                }
            }
            ans1[j]=0;
        }
    }
    vector<int> ans;
    for(int i=1;i<=n;i++){
        if(ans1[i]==1){
            ans.push_back(i);
        }
    }
    cout<<ans.size()<<endl;
    for(int j:ans){
        cout<<j<<' ';
    }
    cout<<endl;
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 28496 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 43 ms 28628 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7568 KB Output is correct
2 Correct 4 ms 7772 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Incorrect 5 ms 7520 KB For each person outside the committee there should be someone in the committee who they dislike.
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 28496 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -