Submission #310884

# Submission time Handle Problem Language Result Execution time Memory
310884 2020-10-08T10:58:58 Z HynDuf Potemkin cycle (CEOI15_indcyc) C++11
30 / 100
429 ms 183672 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], in[NN << 1];
vi g[N], gr[NN << 1];
ii edge[NN];
vi res;
void dfs(int u, int p)
{
    in[u] = 1;
    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 (in[v] && mx < dep[v]) mx = dep[v], mxi = v;
    }
    if (res.empty() && mx != -1)
    {
        while (u != mxi)
        {
            res.eb(edge[u >> 1].F);
            res.eb(edge[u >> 1].S);
            u = par[u];
        }
        res.eb(edge[mxi >> 1].F);
        res.eb(edge[mxi >> 1].S);
    }
    in[u] = 0;
}
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);
            //cerr << "Edge: " << (i << 1) << ' ' << id << '\n';
        }
        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);
            //cerr << "Edge: " << ((i << 1) | 1) << ' ' << id << '\n';
        }
    }
    rep(i, 0, 2 * m - 1) if (!dep[i]) dfs(i, i);
    if (res.empty())
    {
        cout << "no";
        return 0;
    }
    //PR(res, 0, SZ(res) - 1);
    for (int i = 2; i < SZ(res); i += 2)
    {
        if (res[i] != res[i - 1]) swap(res[i], res[i + 1]);
        assert(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 Runtime error 11 ms 10112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 10112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 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 Runtime error 13 ms 10368 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 10880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5760 KB Output is correct
2 Correct 7 ms 5760 KB Output is correct
3 Runtime error 24 ms 15360 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6912 KB Output is correct
2 Correct 11 ms 7040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 22776 KB Output is correct
2 Runtime error 45 ms 19576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 137 ms 51088 KB Output is correct
2 Correct 146 ms 55288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 9356 KB Output is correct
2 Correct 240 ms 8932 KB Output is correct
3 Runtime error 429 ms 183672 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -