답안 #246561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246561 2020-07-09T15:14:11 Z dantoh000 Potemkin cycle (CEOI15_indcyc) C++14
50 / 100
267 ms 4856 KB
#include <bits/stdc++.h>
using namespace std;
int n,m;
int id[1005][1005];
int A[1005];
int B[1005];
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 (id[a][cycle]){
                    //for (auto x : ans) printf("%d ",x);
                    for (int x = 0; x < ans.size(); x++){
                        for (int y = x+2; y < ans.size(); y++){
                            if (id[ans[x]][ans[y]] && (x != 0 || y != ans.size()-1)){ ///xxx illegal operation
                                //printf("%d -> %d illegal \n",ans[x],ans[y]);
                                ///delete everything in it (N * N is ok)
                                ///basically skip everything between x and y
                                ans.erase(ans.begin()+x+1, ans.begin()+y);
                                y = x+1; ///restart check
                            }
                        }
                    }
                    for (auto x : ans) printf("%d ",x);
                    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) {
            dfs(A[i],B[i]);
            ans.clear();
        }
    }

    printf("no");
}

Compilation message

indcyc.cpp: In function 'bool dfs(int, int)':
indcyc.cpp:24:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (int x = 0; x < ans.size(); x++){
                                     ~~^~~~~~~~~~~~
indcyc.cpp:25:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         for (int y = x+2; y < ans.size(); y++){
                                           ~~^~~~~~~~~~~~
indcyc.cpp:26:68: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                             if (id[ans[x]][ans[y]] && (x != 0 || y != ans.size()-1)){ ///xxx illegal operation
                                                                  ~~^~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:47: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:49: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 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 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 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1536 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1536 KB Output is correct
2 Incorrect 15 ms 1664 KB Wrong answer on graph without induced cycle
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 4472 KB Too short sequence
2 Correct 62 ms 4600 KB Too short sequence
3 Incorrect 267 ms 4856 KB Wrong answer on graph without induced cycle
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 4352 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 29 ms 4784 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -