Submission #389201

# Submission time Handle Problem Language Result Execution time Memory
389201 2021-04-13T22:03:19 Z Ahmad_Hasan Potemkin cycle (CEOI15_indcyc) C++17
30 / 100
1000 ms 1988 KB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int> > adj;
vector<int>vis,inst;
stack<int>s;

int f=0;
bool check(int f,int t){
    for(int i=0;i<adj[f].size();i++){
        if(adj[f][i]==t)
            return true;
    }
    return false;
}
void dfs(int cr,int p=-1){
   /// cout<<cr<<' '<<p<<'\n';
    vis[cr]=1;
    s.push(cr);
    inst[cr]=1;
    for(int i=0;i<adj[cr].size()&&!f;i++){
        int nw=adj[cr][i];
        if(inst[nw]&&nw!=p&&!check(nw,p)){
            f=1;
            ///cout<<'h'<<'\n';
            while(s.top()!=nw){
                cout<<s.top()<<' ';
                if(s.top()!=p&&check(cr,s.top())){
                    cout<<'\n';
                    return;
                }
                s.pop();
            }
           /// cout<<s.top()<<'#'<<'\n';
            return;

        }else if(!vis[nw]){
            if(!check(nw,p)){
                dfs(nw,cr);
            }
        }
    }
    if(f)
        return;
    inst[cr]=0;
    s.pop();
}


int32_t main()
{/**
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);*/
    int n,m;
    cin>>n>>m;
    adj.resize(n+5);
    vis=vector<int>(n+5);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    for(int i=1;i<=n;i++){
        s=stack<int>();
        inst=vis=vector<int>(n+5);
        dfs(i);
    }
    if(!f)
        cout<<"no\n";



    return 0;
}

Compilation message

indcyc.cpp: In function 'bool check(int, int)':
indcyc.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<adj[f].size();i++){
      |                 ~^~~~~~~~~~~~~~
indcyc.cpp: In function 'void dfs(int, int)':
indcyc.cpp:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0;i<adj[cr].size()&&!f;i++){
      |                 ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Too short sequence
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Too short sequence
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Wrong adjacency
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 204 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 388 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Incorrect 4 ms 332 KB Wrong adjacency
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 332 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 1124 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 177 ms 852 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 1988 KB Time limit exceeded
2 Halted 0 ms 0 KB -