QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#456978#852. Jellyfishgrass8cow#WA 3ms12188kbC++17790b2024-06-28 19:35:092024-06-28 19:35:09

Judging History

This is the latest submission verdict.

  • [2024-06-28 19:35:09]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 12188kb
  • [2024-06-28 19:35:09]
  • Submitted

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),h=fa[h];
            mm+=(g[h].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=min(mm,3);
    printf("%d\n",ans+mm);
}
int main(){
    int T;scanf("%d",&T);while(T--)sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 12188kb

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:

5
3

result:

wrong answer 1st numbers differ - expected: '4', found: '5'