結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー | hirokazu1020 |
提出日時 | 2018-12-11 01:51:04 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 1,122 bytes |
コンパイル時間 | 782 ms |
コンパイル使用メモリ | 99,948 KB |
実行使用メモリ | 15,304 KB |
最終ジャッジ日時 | 2023-10-24 22:25:21 |
合計ジャッジ時間 | 2,469 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
15,304 KB |
testcase_01 | AC | 16 ms
7,016 KB |
testcase_02 | AC | 36 ms
8,440 KB |
testcase_03 | AC | 24 ms
7,644 KB |
testcase_04 | AC | 18 ms
7,164 KB |
testcase_05 | AC | 23 ms
7,592 KB |
testcase_06 | AC | 43 ms
8,968 KB |
testcase_07 | AC | 42 ms
8,856 KB |
testcase_08 | AC | 25 ms
7,724 KB |
testcase_09 | AC | 17 ms
7,124 KB |
testcase_10 | AC | 9 ms
6,416 KB |
testcase_11 | AC | 45 ms
9,028 KB |
testcase_12 | AC | 37 ms
8,680 KB |
testcase_13 | AC | 39 ms
8,632 KB |
testcase_14 | AC | 33 ms
8,344 KB |
testcase_15 | AC | 23 ms
7,620 KB |
testcase_16 | AC | 7 ms
6,236 KB |
testcase_17 | AC | 24 ms
7,632 KB |
testcase_18 | AC | 43 ms
8,984 KB |
testcase_19 | AC | 38 ms
8,708 KB |
testcase_20 | AC | 41 ms
8,720 KB |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<sstream> #include<cstdio> #include<cstdlib> #include<cstring> #include<climits> #include<cmath> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<numeric> #include<functional> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_set> #include<unordered_map> #include<random> #include<array> #include<cassert> using namespace std; #define INF (1<<29) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define uniq(v) v.erase(unique(all(v)),v.end()) int n; vector<int> edge[100000]; pair<int, int> dfs(int p,int u) { pair<int, int> ret(1, 0); for (int v : edge[u]) { if (p != v) { auto x = dfs(u, v); ret.first += x.second; ret.second += x.first; } } ret.first = max(ret.first, ret.second); return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; rep(i,n-1) { int u, v; cin >> u >> v; u--; v--; edge[u].push_back(v); edge[v].push_back(u); } auto x = dfs(-1, 0); cout << max(x.first, x.second) << endl; return 0; }