結果
問題 | No.1153 ねこちゃんゲーム |
ユーザー | tarattata1 |
提出日時 | 2020-07-11 16:03:57 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,903 bytes |
コンパイル時間 | 1,447 ms |
コンパイル使用メモリ | 100,692 KB |
実行使用メモリ | 65,536 KB |
最終ジャッジ日時 | 2024-11-08 17:58:37 |
合計ジャッジ時間 | 22,314 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,248 KB |
testcase_02 | AC | 4 ms
5,248 KB |
testcase_03 | AC | 4 ms
5,248 KB |
testcase_04 | AC | 4 ms
5,248 KB |
testcase_05 | AC | 4 ms
5,248 KB |
testcase_06 | WA | - |
testcase_07 | AC | 384 ms
42,752 KB |
testcase_08 | AC | 332 ms
42,624 KB |
testcase_09 | WA | - |
testcase_10 | AC | 349 ms
42,624 KB |
testcase_11 | WA | - |
testcase_12 | AC | 318 ms
42,752 KB |
testcase_13 | AC | 350 ms
42,752 KB |
testcase_14 | WA | - |
testcase_15 | AC | 345 ms
42,624 KB |
testcase_16 | WA | - |
testcase_17 | AC | 343 ms
43,392 KB |
testcase_18 | AC | 347 ms
44,288 KB |
testcase_19 | WA | - |
testcase_20 | AC | 348 ms
45,440 KB |
testcase_21 | AC | 349 ms
45,440 KB |
testcase_22 | AC | 333 ms
43,392 KB |
testcase_23 | AC | 328 ms
43,648 KB |
testcase_24 | AC | 330 ms
43,776 KB |
testcase_25 | AC | 349 ms
44,800 KB |
testcase_26 | AC | 339 ms
44,800 KB |
testcase_27 | AC | 340 ms
57,088 KB |
testcase_28 | AC | 424 ms
65,536 KB |
testcase_29 | WA | - |
testcase_30 | AC | 432 ms
63,360 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 209 ms
38,176 KB |
testcase_34 | AC | 207 ms
38,312 KB |
testcase_35 | AC | 195 ms
38,176 KB |
testcase_36 | AC | 192 ms
38,304 KB |
testcase_37 | AC | 122 ms
38,152 KB |
testcase_38 | AC | 100 ms
38,028 KB |
testcase_39 | AC | 105 ms
38,152 KB |
testcase_40 | AC | 111 ms
38,224 KB |
testcase_41 | AC | 99 ms
38,156 KB |
ソースコード
#include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <iterator> #include <cassert> #include <numeric> #include <functional> #include <time.h> #pragma warning(disable:4996) typedef long long ll; typedef unsigned long long ull; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; vector<vector<pair<int, int> > > g; // to, edgeid vector<int> parent; 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()) { break; } auto it = z[curr].find(i); if (it == 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()) { break; } auto it = z[curr].find(i); if (it == z[curr].end()) { break; } } ans[curr] = i; return; } void solve() { int n, m; scanf("%d%d", &n, &m); 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)); } int ret = dfs(-1, 0); dfs2(-1, 0); int sum = 0; int max = -1; int maxi = 0; for (i = 0; i < m; i++) { sum ^= ans[a[i]]; if (max < ans[a[i]]) { max = ans[a[i]]; maxi = i; } } if (sum == 0) { printf("-1 -1\n"); } else { 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(int argc, char* argv[]) { #if 1 solve(); #else int T; scanf("%d", &T); int t; for(t=0; t<T; t++) { //printf("Case #%d: ", t+1); solve(); } #endif return 0; }