Submission #447665

# Submission time Handle Problem Language Result Execution time Memory
447665 2021-07-27T09:34:53 Z fammo Potemkin cycle (CEOI15_indcyc) C++11
30 / 100
1000 ms 2528 KB
#include <bits/stdc++.h>
#pragma GCC target ("sse4.2")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize ("unroll-loops")
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#define file ifstream cin("shufflegold.in"); ofstream cout("shufflegold.out")
#define X first
#define Y second
//#define endl '\n'
typedef pair<int, int> pii;
//#define int long long
const int N = 1000+ 20, MOD = 1e6+7;
int n, m;
vector<int>adj[N];
bool mat[N][N], mark[N];
int dis[N], par[N];

vector<pii>edg;
void bfs(int root){
    for(int i = 0; i < n; i ++)mark[i] = 0, dis[i] = 0, par[i] = -1;
    queue<int>q;
    dis[root] = 0, mark[root] = 1;
    q.push(root);
    while(!q.empty()){
        int v = q.front();
        q.pop();//cout << "IN " << v << endl;
        for(int u = 0; u < n; u ++)if(mat[u][v]){
            if(!mark[u]){
               // cout << "ADD " << u << endl;
                mark[u] = 1;
                par[u] = v;
                dis[u] = dis[v] + 1;
                q.push(u);
            }
        }
    }
    return;
}
int32_t main(){
    fastio;
    //auto t = clock();
    cin >> n >> m;
    for(int i = 0; i < m; i ++){
        int u, v;
        cin >> u >> v;
        v --; u --;
        mat[u][v]= mat[v][u] = 1;
        edg.pb({v, u});
    }
    for(int i = 0; i < m; i ++){
        int u = edg[i].X, v = edg[i].Y;
        mat[u][v] = mat[v][u] = 0;

       // cout << "CHECK " << u+1 << ' ' << v+1 << endl;

        bfs(u);

        if(dis[v] > 2){
            int cur = v;
            while(cur != -1){
                cout << cur+1 << ' ';
                cur = par[cur];
            }
            return 0;
        }
        mat[u][v] = mat[v][u] = 1;
    }
    cout << "no";
    //cout << clock() - t << "ms" << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 460 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 552 ms 716 KB Output is correct
2 Correct 253 ms 716 KB Output is correct
3 Correct 381 ms 716 KB Output is correct
4 Execution timed out 1080 ms 716 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 510 ms 716 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 2256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 1868 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 2528 KB Time limit exceeded
2 Halted 0 ms 0 KB -