답안 #246719

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246719 2020-07-10T02:10:56 Z dantoh000 Potemkin cycle (CEOI15_indcyc) C++14
70 / 100
1000 ms 5608 KB
#include <bits/stdc++.h>
using namespace std;
int n,m;
int id[1005][1005];
int A[100005];
int B[100005];
int vis[100005];
vector<int> ans;
int cycle;
bool dfs(int a, int b){
    vis[id[a][b]] = 2;
    for (int c = 1; c <= n; c++){
        if (c != a && id[b][c] && !id[a][c]){
            if (vis[id[b][c]] == 2){
                cycle = b;
                ans.push_back(b);
                ans.push_back(a);
                return true;
            }
            else if (dfs(b,c)){
                ans.push_back(a);
                if (a == cycle){
                    int s = 0, e = (int)ans.size()-1;
                    for (int x = 0; x < (int)ans.size(); x++){
                        for (int y = x+2; y < (int)ans.size(); y++){
                            if (id[ans[x]][ans[y]] && e-s > y-x){ ///xxx illegal operation
                                //printf("%d -> %d illegal \n",ans[x],ans[y]);
                                /// just take from x to y instead, shorter cycle and guaranteed to be >3 from initial checks
                                s = x, e = y;
                            }
                        }
                    }
                    for (int i = s; i <= e; i++) printf("%d ",ans[i]);
                    exit(0);
                }
                return true;
            }
        }
    }
    vis[id[a][b]] = 1;
    return false;
}
int main(){
    scanf("%d%d",&n,&m);
    for (int i = 1; i <= m; i++){
        scanf("%d%d",&A[i],&B[i]);
        id[B[i]][A[i]] = id[A[i]][B[i]] = i;
    }
    for (int i = 1; i <= m; i++){
        if (vis[i] == 0) {
            assert(id[A[i]][B[i]] == i);
            dfs(A[i],B[i]);
            ans.clear();
        }
    }

    printf("no");
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:44: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:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&A[i],&B[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 7 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 1536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1536 KB Output is correct
2 Correct 17 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 5120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4736 KB Output is correct
2 Correct 321 ms 4704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 3576 KB Output is correct
2 Correct 114 ms 3960 KB Output is correct
3 Correct 23 ms 5504 KB Output is correct
4 Execution timed out 1089 ms 5608 KB Time limit exceeded