QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317721 | #7936. Eliminate Tree | whsyhyyh | WA | 78ms | 39396kb | C++14 | 1.1kb | 2024-01-29 16:05:50 | 2024-01-29 16:05:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int M=1e6+5;
int n;
vector<int>Q[M];
int in[M];
int que[M],L=1,R=0;
bool flag[M];
void Del(int x) {
flag[x]=true;
for(int i=0; i<Q[x].size(); ++i) {
int To=Q[x][i];
if(flag[To])continue;
in[To]--;
if(in[To]<=1)que[++R]=To;
}
}
int main() {
scanf("%d",&n);
for(int i=1; i<n; ++i) {
int u,v;
scanf("%d%d",&u,&v);
Q[u].push_back(v);++in[v];
Q[v].push_back(u);++in[u];
}
for(int i=1; i<=n; ++i)if(in[i]<=1)que[++R]=i;
int cnt=0,ans=0;
while(L<=R) {
int now=que[L++],x=-1;
if(flag[now])continue;
for(int i=0; i<Q[now].size(); ++i) {
int To=Q[now][i];
if(!flag[To]) {x=To;break;}
}
if(~x&&in[x]<=2) {
Del(now);
Del(x);
ans++;
}else {
Del(now);
ans+=2;
}
}
for(int i=1; i<=n; ++i) if(!flag[i]) {
int Mx=2e8;
for(int j=1; j<=Mx; ++j)Mx=2e8;
}
printf("%d",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 31420kb
input:
5 1 2 2 3 3 4 3 5
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 8ms
memory: 31360kb
input:
4 1 2 2 3 3 4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 78ms
memory: 39396kb
input:
196666 32025 108673 181779 17115 162570 134230 93003 39673 89144 1269 185919 154408 34896 65369 35860 44720 55698 1390 45520 189805 147867 124511 135459 132555 87303 18031 176314 59695 33352 130640 87272 39716 35749 108807 143493 94486 126512 116598 40212 70895 132216 80855 22241 188737 150354 17346...
output:
169517
result:
wrong answer 1st numbers differ - expected: '138182', found: '169517'