Submission #1069257

# Submission time Handle Problem Language Result Execution time Memory
1069257 2024-08-21T18:18:04 Z vjudge1 Potemkin cycle (CEOI15_indcyc) C++17
80 / 100
1000 ms 2948 KB
#include <bits/stdc++.h>
using namespace std;

#define ff  first
#define ss  second
#define pb  push_back

const int N = 1005;
const int mod = 1e6 + 7;
const int oo = 2e9;

typedef long long  ll;
typedef pair<int,int>  pii;

vector <int> g[N];

int main() {
    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    #endif // LOCAL

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n, m; cin >> n >> m;

    vector <pii> edges;

    for (int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v;
        u--;v--;
        g[u].pb(v);
        g[v].pb(u);
        edges.pb({u, v});
    }

    for (auto &e : edges) {
        vector <int> npss (n, 0);
        vector <int> di (n, oo);
        vector <int> fat (n, -1);

        npss[e.ss] = 1;
        for (auto &v : g[e.ss]) {
            npss[v] = 1;
        }

        queue <int> q;
        q.push(e.ff);
        di[e.ff] = 0;

        while (q.size()) {
            int u = q.front(); q.pop();
            for (auto &v : g[u]) {
                if (di[v] == oo) {
                    di[v] = di[u] + 1;
                    fat[v] = u;
                    if (npss[v] == 0) q.push(v);
                }
            }
        }

        //cout << e.ff << " " << e.ss << "\n";

        for (int i = 0; i < n; ++i) {
            //cout << i << " " << npss[i] << " " << di[i] << '\n';
            if (i != e.ff && npss[i] && di[i] < oo && di[i] > 1) {
                cout << e.ss + 1 << " ";
                int cur = i;
                while (cur != -1) {
                    cout << cur + 1 << " ";
                    cur = fat[cur];
                }
                cout << '\n';
                return 0;
            }
        }

    }
    cout << "no\n";

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 480 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 28 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 23 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1748 KB Output is correct
2 Correct 19 ms 1180 KB Output is correct
3 Execution timed out 1095 ms 1772 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 1116 KB Output is correct
2 Correct 724 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2768 KB Output is correct
2 Correct 175 ms 2948 KB Output is correct
3 Correct 43 ms 2004 KB Output is correct
4 Execution timed out 1068 ms 2132 KB Time limit exceeded
5 Halted 0 ms 0 KB -