Submission #25096

# Submission time Handle Problem Language Result Execution time Memory
25096 2017-06-20T06:47:26 Z 시제연(#1054) Potemkin cycle (CEOI15_indcyc) C++
30 / 100
1000 ms 4164 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> lis[1100];

int n, m;
int par[1100];
bool chk[1100];
bool adj[1100][1100];

int fin(int a) {return par[a] = ((par[a]==a)?a:fin(par[a]));}
void uni(int a, int b) {
    a = fin(a), b = fin(b);
    par[a] = b;
}

bool vis[1100];
int pa[1100];
void print_path(int v, int q, int r) {
    int i;
    queue<int> qu;
    vis[v] = vis[q] = true;
    pa[v] = -1; pa[q] = v;
    qu.push(q);
    while(!qu.empty()) {
        int here = qu.front();
        qu.pop();
        for (i=0;i<lis[here].size();i++) {
            int there = lis[here][i];
            if (vis[there]||(chk[there]&&there!=r)) continue;
            vis[there] = true;
            qu.push(there);
            pa[there] = here;
            if (there==r) {
                int p = there;
                int cnt = 0;
                while(~p) {
                    printf("%d ",p+1);
                    cnt++;
                    p = pa[p];
                }
                if (cnt<=3) {
                    int a = 1, b = 0;
                    printf("%d\n",a/b);
                }
                printf("\n");
                return;
            }
        }
    }
    while(true) printf("!");
}

bool check(int v) {
    int i, j;
    chk[v] = true;
    for (i=0;i<n;i++) par[i] = i;
    for (i=0;i<lis[v].size();i++) chk[lis[v][i]] = true;
    for (i=0;i<lis[v].size();i++) {
        int q = lis[v][i];
        for (j=0;j<lis[q].size();j++) {
            int r = lis[q][j];
            if (r==v||!chk[r]) continue;
            adj[q][r] = true;
        }
    }
    for (i=0;i<n;i++) {
        if (i==v) continue;
        for (j=0;j<lis[i].size();j++) {
            int there = lis[i][j];
            if (there==v||adj[i][there]) continue;
            uni(i,there);
        }
    }
    for (i=0;i<lis[v].size();i++) {
        int q = lis[v][i];
        for (j=i+1;j<lis[v].size();j++) {
            int r = lis[v][j];
            if (fin(q)==fin(r)&&!adj[q][r]) {
                //printf("%d %d %d\n",v,q,r);
                print_path(v,q,r);
                return true;
            }
        }
    }
    for (i=0;i<lis[v].size();i++) {
        int q = lis[v][i];
        for (j=0;j<lis[q].size();j++) {
            int r = lis[q][j];
            if (r==v||!chk[r]) continue;
            adj[q][r] = false;
        }
    }
    chk[v] = false;
    for (i=0;i<lis[v].size();i++) chk[lis[v][i]] = false;
    return false;
}

int main() {
    int i;

    //freopen("input","r",stdin);

    scanf("%d%d",&n,&m);
    for (i=0;i<m;i++) {
        int a, b;
        scanf("%d%d",&a,&b);
        a--;b--;
        lis[a].push_back(b);
        lis[b].push_back(a);
    }
    for (i=0;i<n;i++) {
        if (check(i)) return 0;
    }
    printf("no\n");

    return 0;
}

Compilation message

indcyc.cpp: In function 'void print_path(int, int, int)':
indcyc.cpp:29:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i=0;i<lis[here].size();i++) {
                   ^
indcyc.cpp: In function 'bool check(int)':
indcyc.cpp:59:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[v].size();i++) chk[lis[v][i]] = true;
               ^
indcyc.cpp:60:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[v].size();i++) {
               ^
indcyc.cpp:62:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<lis[q].size();j++) {
                   ^
indcyc.cpp:70:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<lis[i].size();j++) {
                   ^
indcyc.cpp:76:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[v].size();i++) {
               ^
indcyc.cpp:78:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=i+1;j<lis[v].size();j++) {
                     ^
indcyc.cpp:87:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[v].size();i++) {
               ^
indcyc.cpp:89:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<lis[q].size();j++) {
                   ^
indcyc.cpp:96:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[v].size();i++) chk[lis[v][i]] = false;
               ^
indcyc.cpp: In function 'int main()':
indcyc.cpp:105:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
indcyc.cpp:108:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
                            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3240 KB Output is correct
2 Correct 0 ms 3240 KB Output is correct
3 Correct 0 ms 3240 KB Output is correct
4 Correct 0 ms 3240 KB Output is correct
5 Correct 0 ms 3240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3240 KB Output is correct
2 Execution timed out 1000 ms 3240 KB Execution timed out
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3240 KB Output is correct
2 Execution timed out 1000 ms 3240 KB Execution timed out
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3372 KB Output is correct
2 Correct 0 ms 3372 KB Output is correct
3 Execution timed out 1000 ms 3372 KB Execution timed out
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 3240 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 3768 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 3504 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 4164 KB Output is correct
2 Correct 523 ms 4164 KB Output is correct
3 Execution timed out 1000 ms 4032 KB Execution timed out
4 Halted 0 ms 0 KB -