Submission #25087

# Submission time Handle Problem Language Result Execution time Memory
25087 2017-06-20T06:22:25 Z 시제연(#1054) Potemkin cycle (CEOI15_indcyc) C++
40 / 100
989 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;
                while(~p) {
                    printf("%d ",p+1);
                    p = pa[p];
                }
                printf("\n");
                return;
            }
        }
    }
}

bool check(int v) {
    int i, j;
    memset(chk,0,sizeof(chk)); memset(par,-1,sizeof(par));
    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:53: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:54:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[v].size();i++) {
               ^
indcyc.cpp:56:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<lis[q].size();j++) {
                   ^
indcyc.cpp:64:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<lis[i].size();j++) {
                   ^
indcyc.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[v].size();i++) {
               ^
indcyc.cpp:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=i+1;j<lis[v].size();j++) {
                     ^
indcyc.cpp:81:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[v].size();i++) {
               ^
indcyc.cpp:83:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j=0;j<lis[q].size();j++) {
                   ^
indcyc.cpp:90: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:99: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:102: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 Incorrect 0 ms 3240 KB Unexpected end of file - token expected
# 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 Incorrect 0 ms 3240 KB Unexpected end of file - token expected
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3372 KB Output is correct
2 Correct 0 ms 3372 KB Output is correct
3 Correct 0 ms 3372 KB Too short sequence
4 Incorrect 0 ms 3372 KB Unexpected end of file - token expected
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3240 KB Too short sequence
2 Incorrect 0 ms 3240 KB Unexpected end of file - token expected
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3768 KB Too short sequence
2 Correct 9 ms 3504 KB Too short sequence
3 Correct 989 ms 3768 KB Output is correct
4 Correct 439 ms 3636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3504 KB Too short sequence
2 Incorrect 13 ms 3504 KB Unexpected end of file - token expected
# Verdict Execution time Memory Grader output
1 Correct 66 ms 4164 KB Output is correct
2 Correct 456 ms 4164 KB Output is correct
3 Correct 13 ms 4032 KB Too short sequence
4 Incorrect 19 ms 4032 KB Unexpected end of file - token expected