Submission #231120

# Submission time Handle Problem Language Result Execution time Memory
231120 2020-05-12T19:35:15 Z MKopchev Potemkin cycle (CEOI15_indcyc) C++14
100 / 100
805 ms 2808 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e3+42,mmax=1e5+42;

int n,m;

bool in[nmax][nmax];

vector<int> adj[nmax];

pair<int,int> inp[mmax];

int when[nmax],parent[nmax];

queue< pair<int/*node*/,int/*dist*/> > q,idle;

void test_build(int u,int v)
{
    q=idle;

    for(int i=1;i<=n;i++)when[i]=n+1;

    for(int i=1;i<=n;i++)
        if(in[i][u]&&in[i][v])when[i]=-1;

    q.push({u,0});
    when[u]=0;

    while(q.size())
    {
        pair<int/*node*/,int/*dist*/> tp=q.front();
        q.pop();

        for(auto k:adj[tp.first])
        {
            if(tp.first==u&&k==v)continue;
            if(when[k]>when[tp.first]+1)
            {
                when[k]=when[tp.first]+1;
                q.push({k,when[k]});

                parent[k]=tp.first;
            }
        }
    }
    /*
    cout<<u<<" "<<v<<endl;
    for(int i=1;i<=n;i++)cout<<when[i]<<" ";cout<<endl;
    */
    if(when[v]>n)return;

    printf("%i",v);

    while(v!=u)
    {
        v=parent[v];
        printf(" %i",v);
    }
    printf("\n");
    exit(0);
}
int main()
{
    double t=clock();

    scanf("%i%i",&n,&m);

    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%i%i",&u,&v);

        in[u][v]=1;
        in[v][u]=1;

        inp[i]={u,v};

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    for(int i=1;i<=m&&1.0*(clock()-t)/CLOCKS_PER_SEC<0.8;i++)
        test_build(inp[i].first,inp[i].second);

    printf("no\n");
    return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
indcyc.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i",&u,&v);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 6 ms 800 KB Output is correct
4 Correct 56 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 768 KB Output is correct
2 Correct 51 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2304 KB Output is correct
2 Correct 36 ms 1792 KB Output is correct
3 Correct 805 ms 2336 KB Output is correct
4 Correct 773 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 1792 KB Output is correct
2 Correct 805 ms 1856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 2552 KB Output is correct
2 Correct 203 ms 2560 KB Output is correct
3 Correct 73 ms 2680 KB Output is correct
4 Correct 805 ms 2808 KB Output is correct