結果
問題 | No.1640 簡単な色塗り |
ユーザー | siman |
提出日時 | 2023-02-08 18:18:17 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,006 bytes |
コンパイル時間 | 3,677 ms |
コンパイル使用メモリ | 145,904 KB |
実行使用メモリ | 13,236 KB |
最終ジャッジ日時 | 2024-07-06 05:02:43 |
合計ジャッジ時間 | 17,241 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,812 KB |
testcase_01 | AC | 5 ms
6,812 KB |
testcase_02 | AC | 5 ms
6,944 KB |
testcase_03 | AC | 5 ms
6,944 KB |
testcase_04 | AC | 585 ms
13,096 KB |
testcase_05 | WA | - |
testcase_06 | AC | 6 ms
6,944 KB |
testcase_07 | WA | - |
testcase_08 | AC | 5 ms
6,940 KB |
testcase_09 | AC | 5 ms
6,944 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 15 ms
6,944 KB |
testcase_31 | AC | 108 ms
12,936 KB |
testcase_32 | AC | 75 ms
11,936 KB |
testcase_33 | AC | 65 ms
10,076 KB |
testcase_34 | AC | 66 ms
11,092 KB |
testcase_35 | AC | 52 ms
10,076 KB |
testcase_36 | AC | 16 ms
6,944 KB |
testcase_37 | AC | 19 ms
7,256 KB |
testcase_38 | AC | 88 ms
12,296 KB |
testcase_39 | AC | 41 ms
8,800 KB |
testcase_40 | AC | 35 ms
8,924 KB |
testcase_41 | AC | 63 ms
11,188 KB |
testcase_42 | AC | 39 ms
9,180 KB |
testcase_43 | AC | 44 ms
9,308 KB |
testcase_44 | AC | 41 ms
9,308 KB |
testcase_45 | AC | 32 ms
8,416 KB |
testcase_46 | AC | 16 ms
7,004 KB |
testcase_47 | AC | 11 ms
6,944 KB |
testcase_48 | AC | 77 ms
12,412 KB |
testcase_49 | AC | 8 ms
6,940 KB |
testcase_50 | AC | 5 ms
6,940 KB |
testcase_51 | AC | 5 ms
6,940 KB |
testcase_52 | WA | - |
testcase_53 | WA | - |
07_evil_01.txt | WA | - |
07_evil_02.txt | RE | - |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <limits.h> #include <map> #include <queue> #include <stack> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 200000; vector<int> parent; vector<int> _rank; vector<int> _size; class UnionFind { public: UnionFind(int n) { for (int i = 0; i < n; ++i) { parent.push_back(i); _rank.push_back(0); _size.push_back(1); } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (_rank[x] < _rank[y]) { parent[x] = y; _size[y] += _size[x]; } else { parent[y] = x; _size[x] += _size[y]; if (_rank[x] == _rank[y]) ++_rank[x]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return _size[find(x)]; } }; struct Edge { int id; int from; int to; Edge(int id = -1, int from = -1, int to = -1) { this->id = id; this->from = from; this->to = to; } }; int main() { int N; cin >> N; UnionFind uf(MAX_N); vector<Edge> E[N + 1]; vector<Edge> edges; int a, b; for (int i = 0; i < N; ++i) { cin >> a >> b; uf.unite(a, b); E[a].push_back(Edge(i, a, b)); E[b].push_back(Edge(i, b, a)); edges.push_back(Edge(i, a, b)); } int counter[N + 1]; memset(counter, 0, sizeof(counter)); for (Edge &e : edges) { int x = uf.find(e.from); counter[x]++; } int ans[N]; memset(ans, -1, sizeof(ans)); bool checked[N + 1]; memset(checked, false, sizeof(checked)); for (int v = 1; v <= N; ++v) { if (checked[v]) continue; int e_cnt = counter[uf.find(v)]; if (e_cnt < uf.size(v)) { cout << "No" << endl; return 0; } bool visited[N + 1]; memset(visited, false, sizeof(visited)); stack<int> stk; stk.push(v); int root = -1; int last_eid = -1; while (not stk.empty() && root == -1) { int u = stk.top(); stk.pop(); visited[u] = true; for (Edge &e : E[u]) { if (visited[e.to]) { last_eid = e.id; root = u; break; } stk.push(e.to); } } assert(last_eid != -1); stack<int> new_stk; memset(visited, false, sizeof(visited)); stk = new_stk; stk.push(root); while (not stk.empty()) { int u = stk.top(); stk.pop(); if (visited[u]) continue; visited[u] = true; checked[u] = true; for (Edge &e : E[u]) { if (e.id == last_eid) continue; if (visited[e.to]) continue; ans[e.id] = e.to; stk.push(e.to); } } Edge &le = edges[last_eid]; ans[last_eid] = le.to; } cout << "Yes" << endl; for (int i = 0; i < N; ++i) { cout << ans[i] << endl; } return 0; }