結果

問題 No.1582 Vertexes vs Edges
ユーザー umezo
提出日時 2021-07-03 01:21:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 3,407 ms
コンパイル使用メモリ 194,744 KB
最終ジャッジ日時 2025-01-22 17:04:08
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

vector<int> G[100010];
int dep[100010],par[100010];

void dfs(int v,int p,int d){
  dep[v]=d;
  for(auto nv:G[v]){
    if(nv==p) continue;
    dfs(nv,v,d+1);
  }
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  cin>>n;
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0,-1,0);
  
  int even=0,odd=0;
  rep(i,n){
    if(dep[i]%2==0) even++;
    else odd++;
  }
  cout<<min(even,odd)<<endl;
  
  return 0;
}
0