結果
問題 | No.1295 木と駒 |
ユーザー | QCFium |
提出日時 | 2020-05-27 19:42:42 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,566 bytes |
コンパイル時間 | 1,960 ms |
コンパイル使用メモリ | 177,472 KB |
実行使用メモリ | 35,328 KB |
最終ジャッジ日時 | 2024-07-04 18:34:59 |
合計ジャッジ時間 | 6,989 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 89 ms
11,772 KB |
testcase_17 | AC | 87 ms
11,904 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 95 ms
25,216 KB |
testcase_24 | AC | 94 ms
25,344 KB |
testcase_25 | AC | 63 ms
15,744 KB |
testcase_26 | AC | 80 ms
35,328 KB |
testcase_27 | AC | 76 ms
35,200 KB |
testcase_28 | AC | 126 ms
32,512 KB |
testcase_29 | AC | 75 ms
35,328 KB |
testcase_30 | AC | 75 ms
35,200 KB |
testcase_31 | AC | 74 ms
35,188 KB |
testcase_32 | AC | 108 ms
28,160 KB |
testcase_33 | AC | 70 ms
11,904 KB |
testcase_34 | AC | 74 ms
12,032 KB |
testcase_35 | AC | 72 ms
12,032 KB |
testcase_36 | AC | 70 ms
11,904 KB |
testcase_37 | AC | 68 ms
12,032 KB |
testcase_38 | AC | 71 ms
12,032 KB |
testcase_39 | AC | 71 ms
11,904 KB |
testcase_40 | AC | 73 ms
11,904 KB |
testcase_41 | AC | 55 ms
15,356 KB |
testcase_42 | AC | 59 ms
15,348 KB |
testcase_43 | AC | 57 ms
15,476 KB |
testcase_44 | AC | 56 ms
15,356 KB |
testcase_45 | AC | 55 ms
15,356 KB |
testcase_46 | AC | 56 ms
15,480 KB |
testcase_47 | AC | 61 ms
15,348 KB |
testcase_48 | AC | 60 ms
15,480 KB |
ソースコード
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } /* WA expected */ #define INF 1000000000 struct Payload { bool ok = true; int enabled_id = -1; int id_max = -1; int id_min = INF; Payload operator * (const Payload &rhs) { if (!ok || !rhs.ok) return {false, -1, -1, INF}; if (enabled_id != -1 && rhs.enabled_id != -1) return {false, -1, -1, INF}; int next_enabled = enabled_id != -1 ? enabled_id : rhs.enabled_id; return {true, next_enabled, std::max(id_max, rhs.id_max), std::min(id_min, rhs.id_min)}; } Payload with_par(int i) { Payload res = *this; if (i > res.id_min) res.enabled_id = res.id_min; return res; } void clean(int i, int par) { if (par == -1) par = INF; if (enabled_id != -1 && enabled_id != id_max && (enabled_id != id_min)) ok = false; id_max = id_min = i; if (enabled_id != -1) enabled_id = i; } }; std::vector<std::vector<int> > hen; std::vector<Payload> subtree; void dfs0(int i, int prev) { if (prev != -1) hen[i].erase(std::find(hen[i].begin(), hen[i].end(), prev)); for (auto j : hen[i]) { dfs0(j, i); subtree[i] = subtree[i] * subtree[j]; } bool tmp = prev > subtree[i].id_min; subtree[i].clean(i, prev); if (tmp) subtree[i].enabled_id = i; } std::vector<Payload> omni; void dfs1(int i, int prev, Payload prev_info) { omni[i] = prev_info; for (auto j : hen[i]) omni[i] = omni[i] * subtree[j]; omni[i].clean(i, -1); std::vector<Payload> left(hen[i].size()), right(hen[i].size()); for (int j = 1; j < (int) hen[i].size(); j++) left[j] = left[j - 1] * subtree[hen[i][j - 1]]; for (int j = (int) hen[i].size() - 1; j > 0; j--) right[j - 1] = right[j] * subtree[hen[i][j]]; for (int j = 0; j < (int) hen[i].size(); j++) { auto next = left[j] * right[j] * prev_info; bool tmp = hen[i][j] > next.id_min; next.clean(i, hen[i][j]); if (tmp) next.enabled_id = i; dfs1(hen[i][j], i, next); } } int main() { int n = ri(); hen.resize(n); for (int i = 1; i < n; i++) { int a = ri() - 1; int b = ri() - 1; hen[a].push_back(b); hen[b].push_back(a); } subtree.resize(n); dfs0(0, -1); omni.resize(n); dfs1(0, -1, Payload()); /* for (int i = 0; i < n; i++) { fprintf(stderr, "subtree #%d ok:%d [%d, %d] enabled:%d\n", i, subtree[i].ok, subtree[i].id_min, subtree[i].id_max, subtree[i].enabled_id); } for (int i = 0; i < n; i++) { fprintf(stderr, "omni #%d ok:%d [%d, %d] enabled:%d\n", i, omni[i].ok, omni[i].id_min, omni[i].id_max, omni[i].enabled_id); }*/ for (int i = 0; i < n; i++) puts(omni[i].ok ? "Yes" : "No"); return 0; }