답안 #527419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527419 2022-02-17T11:25:44 Z maomao90 Potemkin cycle (CEOI15_indcyc) C++17
90 / 100
371 ms 94092 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)

template<class T>
inline bool mxto(T &a, T b) {return a < b ? a = b, 1 : 0;}
template<class T>
inline bool mnto(T &a, T b) {return a > b ? a = b, 1 : 0;}

typedef long long ll;
#define FI first
#define SE second
#define MP make_pair
typedef pair<int, int> ii;
#define pb push_back
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<ii> vii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

#define INF 1000000005
#define LINF 1000000000000000005ll
#define MAXN 1005
#define MAXR 200005

int n, r;
vi adj[MAXN], nadj[MAXR];
int grid[MAXN][MAXN];
ii eg[MAXR];
int vis[MAXR];
int p[MAXR];

bool done;
void dfs(int u) {
    vis[u] = 2;
    for (int v : nadj[u]) {
        if (!vis[v]) {
            p[v] = u;
            dfs(v);
            if (done) {
                return;
            }
        } else if (vis[v] == 2) {
            vi tans;
            tans.pb(v);
            while (u != v) {
                assert(u != -1);
                tans.pb(u);
                u = p[u];
            }
            vi ans;
            ans.pb(eg[tans[0]].SE);
            ans.pb(eg[tans[0]].FI);
            REP (i, 1, tans.size() - 1) {
                auto [a, b] = eg[tans[i]];
                assert(a != ans.back());
                assert(grid[ans.back()][a] != -1);
                ans.pb(a);
            }
            REP (i, 0, ans.size()) {
                assert(grid[ans[i]][ans[(i + 1) % ans.size()]] != -1);
            }
            assert(eg[tans.back()] == MP(ans[0], ans.back()));
            for (int i : ans) {
                cout << i << ' ';
            }
            cout << '\n';
            done = 1;
            return;
        }
    }
    vis[u] = 1;
}

int main() {
#ifdef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> r;
    memset(grid, -1, sizeof grid);
    REP (i, 0, r) {
        int a, b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
        grid[a][b] = i;
        grid[b][a] = i + r;
        eg[i] = MP(a, b);
        eg[i + r] = MP(b, a);
    }
    REP (i, 0, 2 * r) {
        auto [a, b] = eg[i];
        REP (j, 1, n + 1) {
            if (j == a) continue;
            if (grid[b][j] == -1) continue;
            if (grid[a][j] != -1) continue;
            nadj[i].pb(grid[b][j]);
            cerr << i << " --- " << grid[b][j] << '\n';
        }
    }
    REP (i, 0, 2 * r) {
        if (vis[i]) continue;
        p[i] = -1;
        dfs(i);
        if (done) {
            return 0;
        }
    }
    cout << "no\n";
}

/*
8 12
1 2
2 3
1 3
2 4
4 5
2 5
5 6
5 7
6 7
3 6
6 8
8 3
*/

Compilation message

indcyc.cpp: In function 'void dfs(int)':
indcyc.cpp:4:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define REP(i, j, k) for (int i = j; i < k; i++)
......
   59 |             REP (i, 1, tans.size() - 1) {
      |                  ~~~~~~~~~~~~~~~~~~~~~  
indcyc.cpp:59:13: note: in expansion of macro 'REP'
   59 |             REP (i, 1, tans.size() - 1) {
      |             ^~~
indcyc.cpp:4:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define REP(i, j, k) for (int i = j; i < k; i++)
......
   65 |             REP (i, 0, ans.size()) {
      |                  ~~~~~~~~~~~~~~~~       
indcyc.cpp:65:13: note: in expansion of macro 'REP'
   65 |             REP (i, 0, ans.size()) {
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8908 KB Output is correct
2 Correct 4 ms 8908 KB Output is correct
3 Correct 4 ms 8908 KB Output is correct
4 Correct 4 ms 8908 KB Output is correct
5 Correct 4 ms 8908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8992 KB Output is correct
2 Correct 4 ms 8908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8908 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9160 KB Output is correct
2 Correct 7 ms 9288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9292 KB Output is correct
2 Correct 10 ms 9336 KB Output is correct
3 Correct 22 ms 11248 KB Output is correct
4 Correct 24 ms 11284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10572 KB Output is correct
2 Correct 11 ms 10676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 25832 KB Output is correct
2 Correct 84 ms 12628 KB Output is correct
3 Correct 249 ms 25736 KB Output is correct
4 Correct 88 ms 12712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 53968 KB Output is correct
2 Correct 138 ms 58288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 12004 KB Output is correct
2 Correct 134 ms 12892 KB Output is correct
3 Correct 350 ms 93484 KB Output is correct
4 Correct 371 ms 94092 KB Output is correct