Submission #371812

# Submission time Handle Problem Language Result Execution time Memory
371812 2021-02-27T05:56:44 Z Andyvanh1 Potemkin cycle (CEOI15_indcyc) C++14
30 / 100
1000 ms 2156 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;

#define vt vector
#define INF INT_MAX
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vt<pair<int,int>> vpii;

vt<vi> adjlist;
vt<bool> visited;

void solve(){
    int n, r;
    cin>>n>>r;
    adjlist.resize(n);
    for(int i = 0; i < r; i++){
        int u, v;
        cin>>u>>v;
        adjlist[u-1].pb(v-1);
        adjlist[v-1].pb(u-1);
    }

    int sz = (1<<n);
    bool bol1 = false;

    for(int j = 1; j < sz; j++){
        bool arr[n];
        for(int i = 0; i < n; i++){
            arr[i] = false;
        }
        int jj = j;
        int idn = 0;
        while(jj!=0){
            if(jj%2==1){
                arr[idn] = true;
            }
            jj/=2;
            idn++;
        }
        vi a;
        for(int i = 0; i < n; i++){
            if(arr[i]){
                a.pb(i);
            }
        }
        if(a.size()<=3){
            continue;
        }
        bool bol = true;
        for(auto& e:a){
            int ct = 0;
            for(auto& ee: adjlist[e]){
                if(arr[ee]){
                    ct++;
                }
            }
            if(ct!=2){
                bol = false;
                break;
            }
        }
        if(bol){
            visited.resize(n);
            for(int i = 0; i < n; i++){
                visited[i] = false;
            }
            vi b;
            stack<int> stk;


            stk.push(a[0]);
            visited[a[0]] = true;
            while(!stk.empty()){

                int node = stk.top();

                stk.pop();
                b.pb(node);
                for(auto&e : adjlist[node]){
                    if(arr[e]&&!visited[e]){
                        stk.push(e);
                        visited[e] = true;
                    }
                }

            }

            for(auto& e: b){
                cout<<e+1<<" ";
            }
            bol1 = true;
            break;
        }

    }
    if(!bol1){
        cout<<"no";
    }
}



int main() {
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Expected integer, but "no" found
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 364 KB Output is correct
2 Incorrect 7 ms 364 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 364 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 1260 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 748 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 2156 KB Time limit exceeded
2 Halted 0 ms 0 KB -