結果
問題 | No.806 木を道に |
ユーザー |
![]() |
提出日時 | 2019-03-23 10:30:06 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 533 bytes |
コンパイル時間 | 1,451 ms |
コンパイル使用メモリ | 161,528 KB |
実行使用メモリ | 9,344 KB |
最終ジャッジ日時 | 2024-09-22 01:37:01 |
合計ジャッジ時間 | 2,683 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define REP(i,a) FOR(i,0,a) using namespace std; ll N; const ll MAX_N=1e5; vector<ll> G[MAX_N]; ll dst[MAX_N]; void dfs(ll v,ll p,ll d){ dst[v]=d; for(auto e:G[v]){ if(e!=p){ dfs(e,v,d+1); } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>N; REP(i,N-1){ ll a,b; cin>>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } ll ans=0; REP(i,N){ ans+=max((ll)G[i].size()-2,0ll); } cout<<ans<<endl; }