結果
問題 | No.1582 Vertexes vs Edges |
ユーザー |
![]() |
提出日時 | 2024-08-07 22:41:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 719 bytes |
コンパイル時間 | 1,211 ms |
コンパイル使用メモリ | 100,684 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-08-07 22:42:03 |
合計ジャッジ時間 | 4,779 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include<iostream>#include<vector>#include<algorithm>using namespace std;using ll = long long;int main(){cin.tie(nullptr);ios::sync_with_stdio(false);int n;cin>>n;vector<vector<int>> g(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);}vector<int> dp1(n,0),dp2(n,0);auto calc = [&](auto calc,int ni,int p) -> void {for(auto&to:g[ni]) if(to!=p) {calc(calc,to,ni);dp1[ni] += dp2[to];dp2[ni] += min(dp1[to],dp2[to]);}dp2[ni]++;};calc(calc,0,-1);int ans = min(dp1[0],dp2[0]);cout<<ans<<endl;}