답안 #788223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
788223 2023-07-20T02:47:30 Z Username4132 Povjerenstvo (COI22_povjerenstvo) C++14
0 / 100
3000 ms 79628 KB
#include<iostream>
#include<vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back

const int MAXN = 500010;
bool del[MAXN], vis[MAXN], ans[MAXN];
int n, m, cn;
vector<int> g[MAXN], gi[MAXN];

void dfs(int v, bool flag){
    vis[v]=true;
    ans[v]=flag;
    for(int to:gi[v]){
        del[to]=true;
        if(!vis[to]) dfs(to, !flag);
    }
}

int main(){
    scanf("%d %d", &n, &m);
    forn(i, m){
        int a, b; scanf("%d %d", &a, &b); --a, --b;
        g[a].PB(b), gi[b].PB(a);
    }
    while(true){
        int v=-1;
        forn(i, n) if(!del[i]) v=i;
        if(v==-1) break;
        forn(i, n) vis[i]=false;
        while(!g[v].empty() && !vis[g[v].back()]) v=g[v].back(), vis[v]=true;
        forn(i, n) vis[v]=false;
        del[v]=true;
        dfs(v, true);
    }
    forn(i, n) cn+=ans[i];
    printf("%d\n", cn);
    forn(i, n) if(ans[i]) printf("%d ", i+1);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:24:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         int a, b; scanf("%d %d", &a, &b); --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 79628 KB Output is correct
2 Correct 175 ms 59240 KB Output is correct
3 Correct 11 ms 23796 KB Output is correct
4 Execution timed out 3065 ms 24252 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 79472 KB Output is correct
2 Execution timed out 3095 ms 41252 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 24280 KB Output is correct
2 Correct 22 ms 23996 KB Output is correct
3 Correct 12 ms 24020 KB Output is correct
4 Execution timed out 3085 ms 24000 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 79628 KB Output is correct
2 Correct 175 ms 59240 KB Output is correct
3 Correct 11 ms 23796 KB Output is correct
4 Execution timed out 3065 ms 24252 KB Time limit exceeded
5 Halted 0 ms 0 KB -