QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#456980 | #852. Jellyfish | grass8cow# | WA | 105ms | 13448kb | C++17 | 823b | 2024-06-28 19:40:52 | 2024-06-28 19:40:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10,mod=1e9+7;
int d[N],n,fa[N];
#define pb push_back
vector<int>g[N];
int ans,mm;
void dfs(int x){
for(int v:g[x]){
if(!d[v])d[v]=d[x]+1,fa[v]=x,dfs(v);
else if(d[v]-d[x]>1){
int h=v;
while(h!=x)mm|=(g[h].size()==2&&g[fa[h]].size()==2),h=fa[h];
mm|=(g[x].size()==2&&g[v].size()==2);
}
}
}
void sol(){
scanf("%d",&n);
ans=mm=0;
for(int i=1;i<=n;i++)g[i].clear(),d[i]=0;
for(int i=1,u,v;i<=n;i++){
scanf("%d%d",&u,&v);
g[u].pb(v),g[v].pb(u);
}
for(int i=1;i<=n;i++)if(g[i].size()==1)ans++;
dfs(1);mm++;
if(!ans)mm++;
printf("%d\n",ans+mm);
}
int main(){
int T;scanf("%d",&T);while(T--)sol();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 12160kb
input:
2 6 1 2 2 3 3 4 4 1 2 5 2 6 4 1 2 2 3 3 4 4 1
output:
4 3
result:
ok 2 number(s): "4 3"
Test #2:
score: -100
Wrong Answer
time: 105ms
memory: 13448kb
input:
85665 6 3 2 4 1 4 6 2 1 2 6 5 1 7 6 2 6 3 5 1 1 2 2 4 4 7 3 7 7 6 1 6 7 1 4 1 3 7 5 5 3 4 2 7 6 2 7 4 7 5 3 1 3 4 2 5 1 4 7 7 2 2 6 5 4 5 6 5 1 3 1 4 6 7 3 5 3 1 3 7 3 2 5 1 5 4 4 6 7 4 5 4 1 3 6 3 7 6 7 6 1 2 1 7 5 3 7 3 1 4 6 2 6 3 2 3 4 3 7 2 3 2 6 2 4 7 5 3 5 5 1 1 4 7 3 4 3 7 5 6 2 7 4 6 6 7 6 ...
output:
4 3 3 3 3 4 4 5 4 5 5 4 3 4 4 3 4 4 4 4 4 5 4 4 3 4 3 9 4 4 3 4 8 3 98 5 4 3 7 4 4 4 4 3 4 4 4 4 5 3 5 4 3 4 96 4 4 4 5 4 3 4 3 5 4 3 4 3 3 4 4 4 4 4 3 4 4 4 3 3 3 4 4 3 4 4 4 4 4 4 3 3 5 5 4 5 4 3 4 4 3 3 4 5 4 4 4 6 4 5 5 5 4 3 5 4 5 3 4 10 4 3 3 4 4 3 5 4 4 3 5 4 4 4 3 3 3 4 5 98 5 105 5 4 4 4 4 ...
result:
wrong answer 11th numbers differ - expected: '4', found: '5'