結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー | fura |
提出日時 | 2020-05-15 10:47:46 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 1,003 bytes |
コンパイル時間 | 2,248 ms |
コンパイル使用メモリ | 207,632 KB |
実行使用メモリ | 19,704 KB |
最終ジャッジ日時 | 2023-10-18 00:46:56 |
合計ジャッジ時間 | 5,055 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
19,704 KB |
testcase_01 | AC | 23 ms
7,032 KB |
testcase_02 | AC | 61 ms
9,672 KB |
testcase_03 | AC | 38 ms
8,088 KB |
testcase_04 | AC | 26 ms
7,296 KB |
testcase_05 | AC | 36 ms
8,088 KB |
testcase_06 | AC | 79 ms
10,728 KB |
testcase_07 | AC | 76 ms
10,464 KB |
testcase_08 | AC | 41 ms
8,352 KB |
testcase_09 | AC | 25 ms
7,032 KB |
testcase_10 | AC | 11 ms
5,936 KB |
testcase_11 | AC | 85 ms
10,728 KB |
testcase_12 | AC | 78 ms
10,200 KB |
testcase_13 | AC | 68 ms
9,936 KB |
testcase_14 | AC | 59 ms
9,408 KB |
testcase_15 | AC | 37 ms
8,088 KB |
testcase_16 | AC | 8 ms
5,732 KB |
testcase_17 | AC | 36 ms
8,088 KB |
testcase_18 | AC | 82 ms
10,728 KB |
testcase_19 | AC | 73 ms
10,200 KB |
testcase_20 | AC | 75 ms
10,200 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; template<class T> struct edge{ int to; T wt; edge(int to,const T& wt):to(to),wt(wt){} }; template<class T> using weighted_graph=vector<vector<edge<T>>>; weighted_graph<int> T; int memo[200000][2]; int dfs(int u,int p,int id,bool b){ // id: 辺 p-u の番号, b: 頂点 u を残すかどうか if(~memo[id][b]) return memo[id][b]; int res; if(b){ res=1; for(auto e:T[u]) if(e.to!=p) { res+=dfs(e.to,u,e.wt,false); } } else{ res=0; for(auto e:T[u]) if(e.to!=p) { res+=max(dfs(e.to,u,e.wt,true),dfs(e.to,u,e.wt,false)); } } return memo[id][b]=res; } int main(){ int n; scanf("%d",&n); T.resize(n); rep(i,n-1){ int u,v; scanf("%d%d",&u,&v); u--; v--; T[u].emplace_back(v,i); T[v].emplace_back(u,i+n); } int ans=0; memset(memo,-1,sizeof memo); rep(u,n){ int tmp=0; for(auto e:T[u]) tmp+=dfs(e.to,u,e.wt,true); ans=max(ans,tmp); } printf("%d\n",ans); return 0; }