結果
| 問題 |
No.763 Noelちゃんと木遊び
|
| コンテスト | |
| ユーザー |
planes
|
| 提出日時 | 2023-03-08 17:25:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 97 ms / 2,000 ms |
| コード長 | 711 bytes |
| コンパイル時間 | 1,870 ms |
| コンパイル使用メモリ | 169,760 KB |
| 実行使用メモリ | 15,104 KB |
| 最終ジャッジ日時 | 2025-03-22 10:42:26 |
| 合計ジャッジ時間 | 4,215 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
vector<vector<ll>> vec;
vector<bool> note;
ll ans=0;
void solve(ll k,ll from) {
ll count=0;
for(auto x:vec[k]) {
if(x==from) continue;
solve(x,k);
if(!note[x]) count++;
}
if(count>0) {
ans+=count;
note[k]=true;
}
return ;
}
int main() {
ll N;cin>>N;
vec=vector<vector<ll>> (N,vector<ll> (0));
note=vector<bool> (N,false);
for(ll i=0;i<N-1;i++) {
ll U,V;cin>>U>>V;
U--;V--;
vec[U].push_back(V);
vec[V].push_back(U);
}
solve(0,0);
if(!note[0]) ans++;
cout<<ans<<endl;
}
planes