結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー | kriii |
提出日時 | 2018-12-11 00:03:43 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 533 bytes |
コンパイル時間 | 372 ms |
コンパイル使用メモリ | 52,692 KB |
実行使用メモリ | 15,000 KB |
最終ジャッジ日時 | 2023-10-24 22:22:28 |
合計ジャッジ時間 | 1,928 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
15,000 KB |
testcase_01 | AC | 14 ms
6,712 KB |
testcase_02 | AC | 30 ms
8,136 KB |
testcase_03 | AC | 21 ms
7,340 KB |
testcase_04 | AC | 16 ms
6,860 KB |
testcase_05 | AC | 21 ms
7,288 KB |
testcase_06 | AC | 37 ms
8,664 KB |
testcase_07 | AC | 35 ms
8,552 KB |
testcase_08 | AC | 23 ms
7,420 KB |
testcase_09 | AC | 16 ms
6,820 KB |
testcase_10 | AC | 8 ms
6,112 KB |
testcase_11 | AC | 37 ms
8,724 KB |
testcase_12 | AC | 33 ms
8,376 KB |
testcase_13 | AC | 34 ms
8,328 KB |
testcase_14 | AC | 30 ms
8,040 KB |
testcase_15 | AC | 21 ms
7,316 KB |
testcase_16 | AC | 6 ms
5,932 KB |
testcase_17 | AC | 22 ms
7,328 KB |
testcase_18 | AC | 37 ms
8,680 KB |
testcase_19 | AC | 33 ms
8,404 KB |
testcase_20 | AC | 34 ms
8,416 KB |
ソースコード
#include <stdio.h> #include <algorithm> #include <vector> using namespace std; int N; vector<int> G[100100]; pair<int, int> go(int x, int l) { pair<int, int> res = {1,0}; for (auto &y : G[x]) if (y != l){ auto u = go(y,x); res.first += max(u.first-1,u.second); res.second += max(u.first,u.second); } return res; } int main() { scanf ("%d",&N); for (int i=1;i<N;i++){ int x,y; scanf ("%d %d",&x,&y); G[x].push_back(y); G[y].push_back(x); } auto p = go(1,0); printf ("%d\n",max(p.first,p.second)); return 0; }