답안 #527393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527393 2022-02-17T10:50:24 Z maomao90 Potemkin cycle (CEOI15_indcyc) C++17
10 / 100
1000 ms 585696 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 100005

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

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] = grid[b][a] = i;
        eg[i] = MP(min(a, b), max(a, b));
    }
    REP (i, 0, r) {
        auto [a, b] = eg[i];
        REP (z, 0, 2) {
            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';
            }
            swap(a, b);
        }
    }
    REP (i, 0, r) {
        if (vis[i]) continue;
        vis[i] = 1;
        dist[i] = 0;
        p[i] = -1;
        queue<int> bfs;
        bfs.push(i);
        cerr << i << '\n';
        while (!bfs.empty()) {
            int u = bfs.front(); bfs.pop();
            cerr << ' ' << u << '\n';
            for (int v : nadj[u]) {
                if (p[u] == v) continue;
                cerr << "  " << v << '\n';
                if (vis[v]) {
                    swap(v, u);
					vi tans;
					while (dist[u] > dist[v]) {
						tans.pb(u);
						u = p[u];
					}
					assert(dist[u] == dist[v]);
					vi rans;
					while (u != v) {
						tans.pb(u);
						rans.pb(v);
						u = p[u];
						v = p[v];
					}
					tans.pb(u);
					reverse(ALL(rans));
					for (int a : rans) {
						tans.pb(a);
					}
                    vi ans;
                    ans.pb(eg[tans[0]].FI);
                    ans.pb(eg[tans[0]].SE);
                    REP (i, 1, tans.size() - 1) {
                        auto [a, b] = eg[tans[i]];
                        if (a == ans.back()) swap(a, b);
                        ans.pb(a);
                    }
                    for (int i : ans) {
                        cout << i << ' ';
                    }
                    cout << '\n';
                    return 0;
                }
                vis[v] = 1;
                p[v] = u;
                dist[v] = dist[u] + 1;
                bfs.push(v);
            }
        }
    }
    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 'int main()':
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++)
......
  101 |                     REP (i, 1, tans.size() - 1) {
      |                          ~~~~~~~~~~~~~~~~~~~~~
indcyc.cpp:101:21: note: in expansion of macro 'REP'
  101 |                     REP (i, 1, tans.size() - 1) {
      |                     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 6604 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 6636 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6604 KB Too short sequence
2 Incorrect 4 ms 6568 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6640 KB Too short sequence
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 6860 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 6860 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8140 KB Too short sequence
2 Incorrect 12 ms 8176 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 232 ms 22052 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 51396 KB Too short sequence
2 Incorrect 114 ms 55408 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 9404 KB Too short sequence
2 Correct 168 ms 9084 KB Output is correct
3 Execution timed out 1117 ms 585696 KB Time limit exceeded
4 Halted 0 ms 0 KB -