結果

問題 No.768 Tapris and Noel play the game on Treeone
ユーザー pekempeypekempey
提出日時 2018-12-16 02:55:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,044 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 84,940 KB
実行使用メモリ 10,200 KB
最終ジャッジ日時 2023-10-25 22:02:05
合計ジャッジ時間 4,220 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,036 KB
testcase_01 AC 3 ms
6,036 KB
testcase_02 AC 3 ms
6,032 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 211 ms
9,984 KB
testcase_19 AC 206 ms
10,004 KB
testcase_20 AC 200 ms
10,200 KB
testcase_21 AC 189 ms
9,920 KB
20evil_special_uni1.txt WA -
20evil_special_uni2.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

vector<int> g[100000];
int dp[100000];
int ans[100000];

int mex(const map<int, int> &mp) {
    int res = 0;
    while (mp.count(res)) res++;
    return res;
}

void dfs(int u, int p) {
    map<int, int> mp;
    for (int v : g[u]) if (v != p) {
        dfs(v, u);
        mp[dp[v]]++;
    }
    dp[u] = mex(mp);
}

void dfs2(int u, int p) {
    map<int, int> mp;
    for (int v : g[u]) {
        mp[dp[v]]++;
    }
    ans[u] = mex(mp);
    for (int v : g[u]) if (v != p) {
        if (mp[dp[v]] == 1 && dp[v] < ans[u]) {
            dp[u] = dp[v];
        }
        dfs2(v, u);
    }
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
    dfs(0, -1);
    dfs2(0, -1);
    cout << count(ans, ans + n, 0) << endl;
    for (int i = 0; i < n; i++) {
        if (ans[i] == 0) {
            cout << i + 1 << endl;
        }
    }
}

0