Submission #134387

# Submission time Handle Problem Language Result Execution time Memory
134387 2019-07-22T14:14:37 Z lyc Potemkin cycle (CEOI15_indcyc) C++14
60 / 100
24 ms 2680 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MAXN = 1e3+5;
const int MAXR = 1e5+5;

int N, R;
vector<int> al[MAXN];
bool conn[MAXN][MAXN];
int pa[MAXN], vis[MAXN];
vector<int> ans;

void solve(int s, int t) {
    //cout << "\t\tSOLVE " << s << " " << t << endl;
    queue<int> q;
    FOR(i,1,N) pa[i] = -1;
    pa[s] = 0;
    for (auto v : al[s]) if (v != t) pa[v] = s, q.push(v);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        if (u == t) break;
        for (auto v : al[u]) if (pa[v] == -1) pa[v] = u, q.push(v);
    }
    for (int u = t; u != 0; u = pa[u]) ans.push_back(u);
    return;
};

void dfs(int u, int p, int a) {
    if (!ans.empty()) return;
    vis[u] = 1;
    for (auto v : al[u]) if (v != p) {
        //cout << "DFS " << u << " " << p << " " << a << endl;
        if (vis[v] == 1) { if (v != a and !conn[u][a] and !conn[v][p]) return solve(u,v); }
        else if (vis[v] == 0) { dfs(v,u,p); if (!ans.empty()) return; }
    }
    vis[u] = 2;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> R;
    FOR(i,1,R){
        int A, B; cin >> A >> B;
        al[A].push_back(B);
        al[B].push_back(A);
        conn[A][B] = conn[B][A] = 1;
    }

    FOR(i,1,N) if (!vis[i] and ans.empty()) { dfs(i,0,0); }

    if (ans.empty()) cout << "no" << '\n';
    else FOR(i,0,SZ(ans)-1) cout << ans[i] << (i<SZ(ans)-1?' ':'\n');
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Too short sequence
2 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Too short sequence
3 Correct 4 ms 760 KB Too short sequence
4 Incorrect 4 ms 824 KB Wrong answer on graph without induced cycle
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Too short sequence
2 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 2296 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1784 KB Too short sequence
2 Correct 8 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2524 KB Too short sequence
2 Correct 24 ms 2460 KB Output is correct
3 Correct 19 ms 2680 KB Too short sequence
4 Incorrect 18 ms 2680 KB Wrong answer on graph without induced cycle