Submission #310868

# Submission time Handle Problem Language Result Execution time Memory
310868 2020-10-08T09:41:36 Z HynDuf Potemkin cycle (CEOI15_indcyc) C++11
10 / 100
1000 ms 746368 KB
#include <bits/stdc++.h>

#define task "I"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1002, NN = 1e5 + 1;
int n, m, dep[NN << 1], par[NN << 1];
bool d[N][N];
vi g[N], gr[NN << 1];
ii edge[NN];
vi res;
void dfs(int u, int p)
{
    par[u] = p;
    dep[u] = dep[p] + 1;
    int mx = -1, mxi = 0;
    for (int v : gr[u]) if (v != p)
    {
        if (!dep[v]) dfs(v, u);
        else if (mx < dep[v]) mx = dep[v], mxi = v;
    }
    if (!res.empty()) return;
    if (mx != -1)
    {
        while (u != mxi)
        {
            int uu = u >> 1;
            res.eb(edge[uu].F);
            res.eb(edge[uu].S);
            u = par[u];
        }
        res.eb(edge[mxi >> 1].F);
        res.eb(edge[mxi >> 1].S);
        return;
    }
}
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> m;
    rep(i, 0, m - 1)
    {
        int u, v;
        cin >> u >> v;
        g[u].eb(i);
        g[v].eb(i);
        d[u][v] = d[v][u] = 1;
        edge[i] = {u, v};
    }
    rep(i, 0, m - 1)
    {
        int u = edge[i].F, v = edge[i].S;
        for (int j : g[v]) if (j != i)
        {
            int id = (edge[j].F == v) ? (j << 1) : ((j << 1) | 1), w = (edge[j].F == v) ? edge[j].S : edge[j].F;
            if (d[u][w]) continue;
            gr[i << 1].eb(id);
        }
        for (int j : g[u]) if (j != i)
        {
            int id = (edge[j].F == u) ? (j << 1) : ((j << 1) | 1), w = (edge[j].F == u) ? edge[j].S : edge[j].F;
            if (d[v][w]) continue;
            gr[(i << 1) | 1].eb(id);
        }
    }
    dfs(0, 0);
    if (res.empty())
    {
        cout << "no";
        return 0;
    }
    for (int i = 2; i < SZ(res); i += 2) if (res[i] != res[i - 1]) swap(res[i], res[i + 1]);
    for (int i = 0; i < SZ(res); i += 2) cout << res[i] << ' ';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5120 KB Repeated vertex
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5120 KB Repeated vertex
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 5248 KB Repeated vertex
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 5376 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1144 ms 746368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 6912 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 22136 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 51064 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 253 ms 8340 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -