QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#594704 | #9420. Find Yourself | ucup-team4757# | WA | 1ms | 9856kb | C++20 | 1.2kb | 2024-09-28 09:48:28 | 2024-09-28 09:48:30 |
Judging History
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;
}
详细
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]