QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594603#9420. Find Yourselfucup-team4757#WA 2ms13944kbC++201.5kb2024-09-28 09:08:322024-09-28 09:08:32

Judging History

This is the latest submission verdict.

  • [2024-09-28 09:08:32]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 13944kb
  • [2024-09-28 09:08:32]
  • Submitted

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 1e6+5;
bool flag;
int hd[N],dfn[N],col[N],low[N],st[N],top,cnt,tim,tot,n,m;
bool tp[N];
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)
{
    dfn[u] = low[u] = ++tim;st[++top] = u;
    for(int i = hd[u],v;i;i = e[i].nex)if((v = e[i].to) != fa)
        if(!dfn[v])tp[v] = !tp[u],dfs(v,u),low[u] = min(low[u],low[v]);
        else
        {
            if(tp[u] == tp[v])flag = 0;
            if(!col[v])low[u] = min(low[u],dfn[v]);
        }
    if(low[u] == dfn[u])
    {
        tot++;int s = 0;
        for(int i = 0;st[top] != u;i++)
            col[st[top--]] = tot,s++;
        if(s > 4)flag = 0;
    }
}
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 = tim = tot = 0;
        for(int i = 1;i <= n;i++)hd[i] = col[i] = dfn[i] = low[i] = 0;
        for(int i = 1;i <= m;i++)
        {
            int u = rd(),v = rd();
            add(u,v);add(v,u);
        }
        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: 13944kb

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: 2ms
memory: 13876kb

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:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO

result:

wrong answer expected YES, found NO [5th token]