답안 #788262

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

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

void dfs1(int v){
    vis[v]=true;
    for(int to:g[v]) if(!vis[to] && !del[to]) dfs1(to);
    order.PB(v);
}

void dfs2(int v){
    vis[v]=true;
    for(int to:gi[v]) if(!vis[to] && !del[to]) dfs2(to);
    lst.PB(v);
}

void dfs3(int v, bool flag){
    del[v]=vis[v]=true;
    ans[v]=flag;
    for(int to:gi[v]) if(!del[to]){
        if(flag) del[to]=true;
        if(!vis[to] && allow[to]) dfs3(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){
        order.clear();
        lst.clear();
        forn(i, n) vis[i]=false;
        forn(i, n) if(!vis[i] && !del[i]) dfs1(i);
        if(order.empty()) break;
        reverse(order.begin(), order.end());
        forn(i, n) vis[i]=false;
        for(int el:order) if(!vis[el]) lst.clear(), dfs2(el);
        int v = lst.back();
        assert(!del[v]);
        forn(i, n) vis[i]=allow[i]=false;
        for(int el:lst) allow[el]=true;
        dfs3(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:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:38:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         int a, b; scanf("%d %d", &a, &b); --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3034 ms 86876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3013 ms 86872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 24504 KB Output is correct
2 Correct 114 ms 24048 KB Output is correct
3 Correct 14 ms 23948 KB Output is correct
4 Correct 120 ms 24116 KB Output is correct
5 Correct 158 ms 24104 KB Output is correct
6 Correct 154 ms 24080 KB Output is correct
7 Correct 160 ms 24084 KB Output is correct
8 Correct 66 ms 24072 KB Output is correct
9 Correct 18 ms 23892 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 24424 KB Output is correct
13 Correct 12 ms 24188 KB Output is correct
14 Correct 14 ms 23792 KB Output is correct
15 Correct 155 ms 24076 KB Output is correct
16 Correct 161 ms 24064 KB Output is correct
17 Correct 160 ms 24068 KB Output is correct
18 Correct 17 ms 23764 KB Output is correct
19 Correct 14 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3034 ms 86876 KB Time limit exceeded
2 Halted 0 ms 0 KB -