QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594704#9420. Find Yourselfucup-team4757#WA 1ms9856kbC++201.2kb2024-09-28 09:48:282024-09-28 09:48:30

Judging History

This is the latest submission verdict.

  • [2024-09-28 09:48:30]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 9856kb
  • [2024-09-28 09:48:28]
  • Submitted

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 1e6+5;
int hd[N],d[N],cnt,n,m;
bool vis[N],tp[N],flag;
struct node{int to,nex;}e[N << 1];
void add(int u,int v)
{e[++cnt] = {v,hd[u]};hd[u] = cnt;}
void dfs(int u,int fa)
{
    d[u] = d[fa]+1;
    for(int i = hd[u],v;i;i = e[i].nex)if((v = e[i].to) != fa)
        if(!vis[v])vis[v] = 1,dfs(v,u);
        else if(!(d[v]-d[u]&1))flag = 0;
        else if(d[v]-d[u] >= 5)flag = 0;
        else if(d[v]-d[u] == 3)
            if(tp[v])flag = 0;
            else tp[v] = 1;
}
inline int rd()
{
    char c;int f = 1;
    while(!isdigit(c = getchar()))if(c=='-')f = -1;
    int x = c-'0';
    while(isdigit(c = getchar()))x = x*10+(c^48);
    return x*f;
}
int main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    for(int t = rd();t--;)
    {
        n = rd();m = rd();flag = 1;cnt = 0;
        for(int i = 1;i <= n;i++)hd[i] = vis[i] = tp[i] = 0;
        for(int i = 1;i <= m;i++)
        {
            int u = rd(),v = rd();
            add(u,v);add(v,u);
        }
        vis[1] = 1;dfs(1,0);
        puts(flag?"YES":"NO");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9852kb

input:

3
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
6 6
1 2
2 3
3 4
4 5
5 6
6 1

output:

NO
YES
NO

result:

ok 3 token(s): yes count is 1, no count is 2

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 9856kb

input:

10
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
2 6
3 7
4 8
9 9
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
2 9
7 8
1 3
1 4
1 5
2 3
2 4
2 5
3 6
4 7
8 8
1 2
2 3
3 4
4 1
1 5
5 6
3 7
7 8
8 8
1 2
2 3
3 4
4 1
1 5
5 6
2 7
3 8
8 8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
9 10
1 3
1 4
1 5
2 3
2 4
2 5
1 6
2 7
3 8
...

output:

YES
YES
YES
YES
YES
YES
NO
YES
YES
YES

result:

wrong answer expected NO, found YES [1st token]