답안 #65503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
65503 2018-08-07T19:41:37 Z 3zp Potemkin cycle (CEOI15_indcyc) C++14
30 / 100
124 ms 12696 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> c,C, v[1009];
int n, m;
stack<int> S;
int f[1009][1009];
int F[1009], P[1009];
int G[1009];
int a[200009], b[200009];
void dfs(int x){
    F[x] = 1;
    c.push_back(x);
    for(int i = 0; i < v[x].size(); i++)
        if(!F[v[x][i]]) dfs(v[x][i]);
}
void dfs1(int x, int en){
    F[x] = 1;

    S.push(x);
    if(x == en){
        while(S.size())
        {
            C.push_back(S.top());
            S.pop();
        }
        return;
    }
    for(int i = 0; i < v[x].size(); i++)
        if(!F[v[x][i]]) dfs1(v[x][i], en);
    S.pop();
}
void fnd(int x, int y, int z){
    for(int i = 0; i <= n; i++)
        F[i] = 1;
    for(int i = 0; i < c.size(); i++)
        F[c[i]] = 0;
    F[x] = 0;
    F[y] = 0;
    F[z] = 0;
    dfs1(y, z);
    for(int i = 0; i < C.size(); i++)
        P[C[i]] = i;
    int X = 0;
    while(1){
        int k = C[X], m1 = k, m2 = X;
        cout << k<<" ";

        if(X == C.size() - 1) break;
        for(int i = 0; i < v[k].size(); i++){
            int p = v[k][i];
            if(P[p] > m2){
                m2 = P[p];
                m1 = p;
            }
        }
        X = m2;
    }
    cout << x << endl;
}
main(){
    cin >> n >> m;
    for(int i =  1; i <= m; i++){
        scanf("%d%d",&a[i],&b[i]);
        f[a[i]][b[i]] = 1;
        f[b[i]][a[i]] = 1;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++)
            F[j] = 0, v[j].clear();
        F[i] = 1;
        for(int j = 1; j <= m; j++){
            int x = a[j], y = b[j];
            if(x == i){
                F[y] = 2;
                continue;
            }
            if(y == i){
                F[x] = 2;
                continue;
            }
            if(f[i][x] && f[i][y]) continue;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        for(int j = 1; j <= n; j++){
            if(!F[j]){
                c.clear();
                dfs(j);
                vector<int> g;
                for(int k = 0; k < c.size(); k++){
                    for(int t = 0;  t < v[c[k]].size(); t++){
                        int x = v[c[k]][t];
                        if(G[x] == 0 && F[x] == 2){
                            g.push_back(x);
                            G[x] = 1;
                        }
                    }
                }
                for(int i = 0; i < g.size(); i++)
                    G[g[i]] = 0;
                for(int i1 = 0; i1 < g.size(); i1++){
                    for(int j = i1 + 1; j < g.size(); j++){
                        if(f[g[i1]][g[j]]) continue;
                        fnd(i, g[i1], g[j]);
                        return 0;
                    }
                }
            }

        }
    }
    cout<<"no"<<endl;
}

Compilation message

indcyc.cpp: In function 'void dfs(int)':
indcyc.cpp:13:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v[x].size(); i++)
                    ~~^~~~~~~~~~~~~
indcyc.cpp: In function 'void dfs1(int, int)':
indcyc.cpp:28:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v[x].size(); i++)
                    ~~^~~~~~~~~~~~~
indcyc.cpp: In function 'void fnd(int, int, int)':
indcyc.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < c.size(); i++)
                    ~~^~~~~~~~~~
indcyc.cpp:41:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < C.size(); i++)
                    ~~^~~~~~~~~~
indcyc.cpp:48:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(X == C.size() - 1) break;
            ~~^~~~~~~~~~~~~~~
indcyc.cpp:49:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < v[k].size(); i++){
                        ~~^~~~~~~~~~~~~
indcyc.cpp:45:23: warning: variable 'm1' set but not used [-Wunused-but-set-variable]
         int k = C[X], m1 = k, m2 = X;
                       ^~
indcyc.cpp: At global scope:
indcyc.cpp:60:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
indcyc.cpp: In function 'int main()':
indcyc.cpp:90:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int k = 0; k < c.size(); k++){
                                ~~^~~~~~~~~~
indcyc.cpp:91:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for(int t = 0;  t < v[c[k]].size(); t++){
                                     ~~^~~~~~~~~~~~~~~~
indcyc.cpp:99:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int i = 0; i < g.size(); i++)
                                ~~^~~~~~~~~~
indcyc.cpp:101:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int i1 = 0; i1 < g.size(); i1++){
                                 ~~~^~~~~~~~~~
indcyc.cpp:102:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for(int j = i1 + 1; j < g.size(); j++){
                                         ~~^~~~~~~~~~
indcyc.cpp:63: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 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 3 ms 744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2592 KB Output is correct
2 Runtime error 7 ms 3396 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 3472 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 10840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 10840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 10840 KB Output is correct
2 Correct 124 ms 10840 KB Output is correct
3 Runtime error 68 ms 12696 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -