Submission #788233

# Submission time Handle Problem Language Result Execution time Memory
788233 2023-07-20T02:58:07 Z Username4132 Povjerenstvo (COI22_povjerenstvo) C++14
0 / 100
3000 ms 80568 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){
            if(del[i]) g[i].clear(), gi[i].clear();
            else{
                vector<int> keep, ki;
                for(int el:g[i]) if(!del[el]) keep.PB(el);
                for(int el:gi[i]) if(!del[el]) ki.PB(el);
                swap(g[i], keep);
                swap(gi[i], ki);
            }
        }
    }
    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;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 173 ms 80568 KB Output is correct
2 Correct 245 ms 60188 KB Output is correct
3 Correct 15 ms 23848 KB Output is correct
4 Execution timed out 3084 ms 24228 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 168 ms 80332 KB Output is correct
2 Execution timed out 3046 ms 42140 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 24276 KB Output is correct
2 Correct 99 ms 24004 KB Output is correct
3 Correct 14 ms 24020 KB Output is correct
4 Incorrect 194 ms 24056 KB There must not be two people within the committee such that one person dislikes the other.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 173 ms 80568 KB Output is correct
2 Correct 245 ms 60188 KB Output is correct
3 Correct 15 ms 23848 KB Output is correct
4 Execution timed out 3084 ms 24228 KB Time limit exceeded
5 Halted 0 ms 0 KB -