結果

問題 No.1153 ねこちゃんゲーム
ユーザー nikkukunnikkukun
提出日時 2020-08-14 16:56:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,753 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 166,536 KB
実行使用メモリ 64,768 KB
最終ジャッジ日時 2024-04-18 18:43:43
合計ジャッジ時間 22,497 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,320 KB
testcase_01 AC 6 ms
8,320 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 7 ms
8,448 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 236 ms
48,000 KB
testcase_08 WA -
testcase_09 AC 207 ms
48,192 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 241 ms
48,168 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 241 ms
48,164 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 230 ms
48,128 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 248 ms
57,088 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 96 ms
48,660 KB
testcase_39 AC 107 ms
48,484 KB
testcase_40 WA -
testcase_41 AC 89 ms
48,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 15:36 - 15:56
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 2e5 + 5;
const int K = 18 + 2;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

vector<int> a[N];
int sg[N], cnt[N][K];
int rt[N], nxt[N][K];
int pos[N];

int Mex(int cnt[]) {
	for (int i = 0; i < K; i++)
		if (cnt[i] == 0)
			return i;
	return -1; // impossible
}

void DFS(int u, int pa) {
	for (auto v: a[u]) {
		if (v == pa) continue;
		DFS(v, u);
		cnt[u][sg[v]]++;
	}
	sg[u] = Mex(cnt[u]);
}

void Cal(int u, int pa, int sgPa) {
	// update sg(u)
	if (sgPa != -1) {
		nxt[u][sgPa] = pa;
		cnt[u][sgPa]++;
		sg[u] = Mex(cnt[u]);
	}
	rt[u] = sg[u];

	// top-down
	for (auto v: a[u]) {
		if (v == pa) continue;
		nxt[u][sg[v]] = v;
		cnt[u][sg[v]]--;
		int sgNew = cnt[u][sg[v]] ? sg[u] : sg[v];
		Cal(v, u, sgNew);
		cnt[u][sg[v]]++;
	}

	// restore sg(u)
	if (sgPa != -1) {
		cnt[u][sgPa]--;
		sg[u] = Mex(cnt[u]);
	}
}

int main() {
	ios::sync_with_stdio(0);

	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
		cin >> pos[i];
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	DFS(1, 0);
	Cal(1, 0, -1);

	int sgSum = 0;
	for (int i = 1; i <= m; i++)
		sgSum ^= rt[pos[i]];
	if (sgSum == 0) {
		cout << "-1 -1" << endl;
		return 0;
	}

	for (int i = 1; i <= m; i++) {
		int u = pos[i];
		int need = rt[u] ^ sgSum;
		if (need >= K) continue;
		if (nxt[u][need]) {
			cout << i << ' ' << nxt[u][need] << endl;
			return 0;
		}
	}

	return 0;
}
0