結果
問題 | No.1153 ねこちゃんゲーム |
ユーザー | tarattata1 |
提出日時 | 2020-08-07 00:29:55 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 421 ms / 2,500 ms |
コード長 | 3,309 bytes |
コンパイル時間 | 2,109 ms |
コンパイル使用メモリ | 87,352 KB |
実行使用メモリ | 65,520 KB |
最終ジャッジ日時 | 2023-10-22 03:01:33 |
合計ジャッジ時間 | 22,774 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 3 ms
4,348 KB |
testcase_03 | AC | 3 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 3 ms
4,348 KB |
testcase_07 | AC | 342 ms
42,552 KB |
testcase_08 | AC | 348 ms
42,816 KB |
testcase_09 | AC | 347 ms
42,552 KB |
testcase_10 | AC | 337 ms
42,816 KB |
testcase_11 | AC | 346 ms
42,552 KB |
testcase_12 | AC | 339 ms
42,816 KB |
testcase_13 | AC | 336 ms
42,552 KB |
testcase_14 | AC | 338 ms
42,552 KB |
testcase_15 | AC | 329 ms
42,816 KB |
testcase_16 | AC | 335 ms
42,816 KB |
testcase_17 | AC | 344 ms
43,344 KB |
testcase_18 | AC | 355 ms
44,136 KB |
testcase_19 | AC | 357 ms
44,136 KB |
testcase_20 | AC | 358 ms
45,720 KB |
testcase_21 | AC | 361 ms
45,720 KB |
testcase_22 | AC | 347 ms
43,344 KB |
testcase_23 | AC | 353 ms
43,872 KB |
testcase_24 | AC | 353 ms
43,872 KB |
testcase_25 | AC | 355 ms
44,928 KB |
testcase_26 | AC | 354 ms
44,928 KB |
testcase_27 | AC | 363 ms
57,072 KB |
testcase_28 | AC | 421 ms
65,520 KB |
testcase_29 | AC | 417 ms
63,672 KB |
testcase_30 | AC | 411 ms
63,408 KB |
testcase_31 | AC | 360 ms
48,096 KB |
testcase_32 | AC | 206 ms
38,328 KB |
testcase_33 | AC | 208 ms
38,324 KB |
testcase_34 | AC | 203 ms
38,332 KB |
testcase_35 | AC | 208 ms
38,324 KB |
testcase_36 | AC | 203 ms
38,328 KB |
testcase_37 | AC | 116 ms
38,048 KB |
testcase_38 | AC | 103 ms
38,048 KB |
testcase_39 | AC | 109 ms
38,048 KB |
testcase_40 | AC | 114 ms
38,044 KB |
testcase_41 | AC | 101 ms
38,044 KB |
ソースコード
#include <cstdio> #include <cstdlib> #include <vector> #include <map> #include <iterator> #include <cassert> #pragma warning(disable:4996) #define INF 2140000000 using namespace std; vector<vector<pair<int, int> > > g; // to, edgeid vector<int> parent; // parent[i]: parent of vertex i vector<int> val; // val[2*i]:val for downward dir, val[2*i+1]: val for upward dir vector<map<int, int> > z; // z[i]: vals conter for directed edges from vertex i vector<int> ans; // ans[i]: Grundy number for vertex i int dfs(int par, int curr) { parent[curr] = par; int i; for (i = 0; i < (int)g[curr].size(); i++) { int next = g[curr][i].first; int edge = g[curr][i].second; if (next == par) continue; int tmp = dfs(curr, next); val[edge * 2] = tmp; z[curr][tmp]++; } for (i = 0; i < INF; i++) { if (z[curr].empty() || z[curr].find(i) == z[curr].end()) { break; } } return i; } void dfs2(int par, int curr) { int i; for (i = 0; i < (int)g[curr].size(); i++) { int next = g[curr][i].first; int edge = g[curr][i].second; if (next == par) continue; int k; for (k = 0; k < INF; k++) { if (z[curr].empty()) { break; } auto it = z[curr].find(k); if (it == z[curr].end()) { break; } int num=it->second; if (val[edge*2]==k) num--; if (num < 1) { break; } } val[edge * 2 + 1] = k; z[next][k]++; dfs2(curr, next); } for (i = 0; i < INF; i++) { if (z[curr].empty() || z[curr].find(i) == z[curr].end()) { break; } } ans[curr] = i; return; } void solve() { int n, m; scanf("%d%d", &n, &m); assert(n >= 1 && n <= 200000); assert(m >= 1 && m <= 200000); vector<int> a(m); int i; for (i = 0; i < m; i++) { scanf("%d", &a[i]); a[i]--; } g.resize(n); parent.resize(n); z.resize(n); ans.resize(n); val.resize((n-1) * 2); for (i = 0; i < n - 1; i++) { int p, q; scanf("%d%d", &p, &q); p--; q--; g[p].push_back(make_pair(q, i)); g[q].push_back(make_pair(p, i)); } dfs(-1, 0); dfs2(-1, 0); int sum = 0; for (i = 0; i < m; i++) { sum ^= ans[a[i]]; } if (sum == 0) { printf("-1 -1\n"); } else { int max = -1; int maxi = -1; for (i = 0; i < m; i++) { int tmp = ans[a[i]] & sum; if (max < tmp) { max = tmp; maxi = i; } } int target = ans[a[maxi]]^sum; int nextvtx = -1; for (i = 0; i < (int)g[a[maxi]].size(); i++) { int next = g[a[maxi]][i].first; int edge = g[a[maxi]][i].second; int tmpval = (next == parent[a[maxi]] ? val[2 * edge + 1] : val[2 * edge]); if (target == tmpval) { nextvtx = next; break; } } printf("%d %d\n", maxi + 1, nextvtx + 1); } return; } int main() { solve(); return 0; }