提出 #2124277
ソースコード 拡げる
#include<cstdio>
#include<vector>
using namespace std;
const int maxn=100000;
int n,f[maxn+10];
vector<int> g[maxn+10];
void dfs(int x,int fa){
bool isb=0;
for(int i=0;i<g[x].size();++i){
int e=g[x][i]; if(e!=fa){
dfs(e,x); f[x]+=f[e];
if(!f[e]) if(!isb) isb=1; else ++f[x];
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<n;++i){
int l,r; scanf("%d%d",&l,&r); ++l; ++r;
g[l].push_back(r); g[r].push_back(l);
}
for(int i=1;i<=n;++i) if(g[i].size()>2){
dfs(i,0); printf("%d",f[i]); return 0;
}
printf("1");
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Antennas on Tree |
| ユーザ | nqiiii |
| 言語 | C++14 (GCC 5.4.1) |
| 得点 | 900 |
| コード長 | 557 Byte |
| 結果 | AC |
| 実行時間 | 42 ms |
| メモリ | 10368 KiB |
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:17:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:19:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int l,r; scanf("%d%d",&l,&r); ++l; ++r;
^
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 900 / 900 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 0_00.txt, 0_01.txt, 0_02.txt |
| All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 0_00.txt | AC | 2 ms | 2560 KiB |
| 0_01.txt | AC | 2 ms | 2560 KiB |
| 0_02.txt | AC | 2 ms | 2560 KiB |
| 1_00.txt | AC | 2 ms | 2560 KiB |
| 1_01.txt | AC | 2 ms | 2560 KiB |
| 1_02.txt | AC | 2 ms | 2560 KiB |
| 1_03.txt | AC | 2 ms | 2560 KiB |
| 1_04.txt | AC | 2 ms | 2560 KiB |
| 1_05.txt | AC | 2 ms | 2560 KiB |
| 1_06.txt | AC | 34 ms | 5760 KiB |
| 1_07.txt | AC | 28 ms | 6136 KiB |
| 1_08.txt | AC | 33 ms | 5760 KiB |
| 1_09.txt | AC | 28 ms | 6136 KiB |
| 1_10.txt | AC | 42 ms | 10368 KiB |
| 1_11.txt | AC | 40 ms | 8064 KiB |
| 1_12.txt | AC | 38 ms | 6400 KiB |
| 1_13.txt | AC | 40 ms | 6144 KiB |
| 1_14.txt | AC | 39 ms | 6144 KiB |
| 1_15.txt | AC | 39 ms | 6144 KiB |
| 1_16.txt | AC | 39 ms | 6144 KiB |
| 1_17.txt | AC | 39 ms | 6272 KiB |
| 1_18.txt | AC | 35 ms | 6400 KiB |
| 1_19.txt | AC | 34 ms | 6656 KiB |
| 1_20.txt | AC | 33 ms | 6528 KiB |
| 1_21.txt | AC | 33 ms | 6400 KiB |
| 1_22.txt | AC | 31 ms | 6136 KiB |