結果

問題 No.1582 Vertexes vs Edges
ユーザー shiomusubi496
提出日時 2021-07-02 22:34:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 445 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 196,328 KB
最終ジャッジ日時 2025-01-22 16:27:11
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
int N;
vector<int> G[1<<20];
pair<int,int>dfs(int v,int p){
  pair<int,int> res{0,1};
  for(int t:G[v])if(t!=p){
    auto[a,b]=dfs(t,v);
    res.first+=b;
    res.second+=min(a,b);
  }
  return res;
}
signed main(){
  cin>>N;
  for(int i=0;i<N-1;i++){
    int a,b; cin>>a>>b;
    G[--a].push_back(--b);
    G[b].push_back(a);
  }
  auto[a,b]=dfs(0,-1);
  cout<<min(a,b)<<endl;
}
0