Submission #244563

# Submission time Handle Problem Language Result Execution time Memory
244563 2020-07-04T09:50:30 Z dantoh000 Potemkin cycle (CEOI15_indcyc) C++14
70 / 100
1000 ms 5112 KB
#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<int> G[1005];
int K[1005][1005];
int p[1005];
queue<int> q;
int main(){
    scanf("%d%d",&n,&m);
    for (int i = 0; i < m; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
        K[u][v] = K[v][u] = 1;
    }
    for (int i = 1; i <= n; i++) K[i][i] = 1;
    for (int i = 1; i <= n; i++){
        for (auto U : G[i]){
            for (auto V : G[i]){
                if (!K[U][V]){
                    //printf("test %d %d %d\n",i,U,V);
                    p[U] = U;
                    q.push(U);
                    while (q.size()){
                        int u = q.front(); q.pop();
                        for (auto v: G[u]){
                            if ((v == V || !K[v][i]) && p[v] == 0){
                                p[v] = u;
                                //printf("%d -> %d\n",u,v);
                                q.push(v);
                            }
                        }
                    }
                    if (p[V]){
                        vector<int> ans;
                        int cur = V;
                        while (cur != U){
                            ans.push_back(cur);
                            cur = p[cur];
                        }
                        ans.push_back(U);
                        ans.push_back(i);
                        for (auto x : ans) printf("%d ",x);
                        return 0;
                    }
                    for (int i = 1; i <= n; i++) p[i] = 0;
                }
            }
        }
    }
    printf("no");
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
indcyc.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&u,&v);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 16 ms 812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 1664 KB Output is correct
2 Correct 7 ms 1664 KB Output is correct
3 Correct 7 ms 1536 KB Output is correct
4 Correct 164 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1664 KB Output is correct
2 Correct 207 ms 1632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 4864 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 111 ms 4608 KB Output is correct
2 Execution timed out 1095 ms 4608 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3064 KB Output is correct
2 Correct 144 ms 3064 KB Output is correct
3 Correct 432 ms 5112 KB Output is correct
4 Execution timed out 1090 ms 4992 KB Time limit exceeded