結果
問題 | No.1153 ねこちゃんゲーム |
ユーザー | tarattata1 |
提出日時 | 2020-07-11 15:59:43 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,903 bytes |
コンパイル時間 | 1,307 ms |
コンパイル使用メモリ | 100,956 KB |
実行使用メモリ | 65,408 KB |
最終ジャッジ日時 | 2024-11-08 17:54:14 |
合計ジャッジ時間 | 24,878 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | AC | 4 ms
5,248 KB |
testcase_04 | AC | 3 ms
5,248 KB |
testcase_05 | AC | 3 ms
5,248 KB |
testcase_06 | WA | - |
testcase_07 | AC | 370 ms
42,752 KB |
testcase_08 | AC | 333 ms
42,624 KB |
testcase_09 | WA | - |
testcase_10 | AC | 343 ms
42,624 KB |
testcase_11 | WA | - |
testcase_12 | AC | 340 ms
42,880 KB |
testcase_13 | AC | 345 ms
42,624 KB |
testcase_14 | WA | - |
testcase_15 | AC | 327 ms
42,624 KB |
testcase_16 | WA | - |
testcase_17 | AC | 309 ms
43,392 KB |
testcase_18 | AC | 306 ms
44,032 KB |
testcase_19 | WA | - |
testcase_20 | AC | 335 ms
45,440 KB |
testcase_21 | WA | - |
testcase_22 | AC | 312 ms
43,264 KB |
testcase_23 | AC | 318 ms
43,648 KB |
testcase_24 | WA | - |
testcase_25 | AC | 328 ms
44,800 KB |
testcase_26 | AC | 322 ms
44,928 KB |
testcase_27 | WA | - |
testcase_28 | AC | 365 ms
65,408 KB |
testcase_29 | WA | - |
testcase_30 | AC | 365 ms
63,360 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 193 ms
38,176 KB |
testcase_34 | WA | - |
testcase_35 | AC | 189 ms
38,176 KB |
testcase_36 | WA | - |
testcase_37 | AC | 118 ms
38,156 KB |
testcase_38 | AC | 104 ms
38,028 KB |
testcase_39 | WA | - |
testcase_40 | AC | 116 ms
38,028 KB |
testcase_41 | AC | 102 ms
38,148 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; }