結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
![]() |
提出日時 | 2018-12-11 00:03:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 533 bytes |
コンパイル時間 | 368 ms |
コンパイル使用メモリ | 49,408 KB |
実行使用メモリ | 15,488 KB |
最終ジャッジ日時 | 2025-03-22 10:32:13 |
合計ジャッジ時間 | 2,172 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf ("%d",&N); | ~~~~~~^~~~~~~~~ main.cpp:24:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | int x,y; scanf ("%d %d",&x,&y); | ~~~~~~^~~~~~~~~~~~~~~
ソースコード
#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; }