답안 #310907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310907 2020-10-08T12:30:21 Z HynDuf Potemkin cycle (CEOI15_indcyc) C++11
100 / 100
345 ms 90232 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 = 1001, NN = 1e5 + 1;
int n, m, 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;
    for (int v : gr[u])
    {
        if (par[v] == -1) dfs(v, u);
        else if (in[v] && res.empty())
        {
            while (u != v)
            {
                res.eb(edge[u >> 1].F);
                res.eb(edge[u >> 1].S);
                u = par[u];
            }
            res.eb(edge[v >> 1].F);
            res.eb(edge[v >> 1].S);
            return;
        }
    }
    in[u] = 0;
}
void fix()
{
    for (int i = 2; i < SZ(res); i += 2) if (res[i] != res[i - 1]) swap(res[i], res[i + 1]);

}
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);
        }
    }
    fill(par, par + 2 * m, -1);
    rep(i, 0, 2 * m - 1) if (par[i] == -1 && res.empty()) dfs(i, i);
    if (res.empty())
    {
        cout << "no";
        return 0;
    }
    fix();
    if (res[1] != res[2])
    {
        swap(res[0], res[1]);
        fix();
    }
    for (int i = 0; i < SZ(res); i += 2) cout << res[i] << ' ';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5376 KB Output is correct
2 Correct 6 ms 5504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5760 KB Output is correct
2 Correct 9 ms 5760 KB Output is correct
3 Correct 18 ms 7680 KB Output is correct
4 Correct 14 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6912 KB Output is correct
2 Correct 11 ms 7040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 22304 KB Output is correct
2 Correct 39 ms 9596 KB Output is correct
3 Correct 113 ms 22264 KB Output is correct
4 Correct 32 ms 9724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 50936 KB Output is correct
2 Correct 157 ms 55160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 8388 KB Output is correct
2 Correct 242 ms 8184 KB Output is correct
3 Correct 307 ms 90232 KB Output is correct
4 Correct 345 ms 90232 KB Output is correct