QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#219629 | #5307. Subgraph Isomorphism | isaunoya | WA | 40ms | 5912kb | C++23 | 2.2kb | 2023-10-19 16:52:36 | 2023-10-19 16:52:36 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<random>
#include<chrono>
#include<queue>
#include<map>
using namespace std;
const int N=100005;
const unsigned long long mask=std::chrono::steady_clock::now().time_since_epoch().count();
const unsigned long long S=1;
unsigned long long shift(unsigned long long x)
{
x^=mask;
x^=x<<13;
x^=x>>7;
x^=x<<17;
x^=mask;
return x;
}
int n,m;
vector<int>G[N];
int deg[N];
bool vis[N];
unsigned long long f[N];
void dfs(int u)
{
f[u]=S;
vis[u]=true;
for(int v:G[u])
{
if(vis[v]) continue;
dfs(v);
f[u]+=shift(f[v]);
}
return;
}
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
G[i].clear(),deg[i]=0;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
G[x].emplace_back(y);
G[y].emplace_back(x);
deg[x]++,deg[y]++;
}
if(m==n-1)
{
cout<<"YES\n";
return;
}
if(m>n)
{
cout<<"NO\n";
return;
}
queue<int>q;
for(int i=1;i<=n;i++)
if(deg[i]==1) q.emplace(i);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int v:G[u])
{
deg[v]--;
if(deg[v]==1) q.emplace(v);
}
}
for(int i=1;i<=n;i++)
if(deg[i]==2) vis[i]=true;
else vis[i]=false;
for(int i=1;i<=n;i++)
if(deg[i]==2) dfs(i);
vector<int>pos;
for(int i=1;i<=n;i++)
if(deg[i]==2)
{
q.emplace(i);
deg[i]--;
break;
}
while(!q.empty())
{
int u=q.front();
q.pop();
pos.emplace_back(u);
for(int v:G[u])
{
deg[v]--;
if(deg[v]==1) q.emplace(v);
}
}
int l=pos.size();
bool all_same=true;
for(int i=1;i<l;i++)
if(f[pos[i]]!=f[pos[i-1]])
{
all_same=false;
break;
}
bool gap_same=false;
if(l%2==0)
{
gap_same=true;
for(int i=2;i<l;i++)
if(f[pos[i]]!=f[pos[i-2]])
{
gap_same=false;
break;
}
}
if(all_same||gap_same) cout<<"YES\n";
else cout<<"NO\n";
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int T;
cin>>T;
while(T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5912kb
input:
4 7 6 1 2 2 3 3 4 4 5 5 6 3 7 3 3 1 2 2 3 3 1 5 5 1 2 2 3 3 4 4 1 1 5 1 0
output:
YES YES NO YES
result:
ok 4 token(s): yes count is 3, no count is 1
Test #2:
score: -100
Wrong Answer
time: 40ms
memory: 5804kb
input:
33192 2 1 1 2 3 2 1 3 2 3 3 3 1 2 1 3 2 3 4 3 1 4 2 4 3 4 4 3 1 3 1 4 2 4 4 4 1 3 1 4 2 4 3 4 4 4 1 3 1 4 2 3 2 4 4 5 1 3 1 4 2 3 2 4 3 4 4 6 1 2 1 3 1 4 2 3 2 4 3 4 5 4 1 5 2 5 3 5 4 5 5 4 1 4 1 5 2 5 3 5 5 5 1 4 1 5 2 5 3 5 4 5 5 5 1 4 1 5 2 4 3 5 4 5 5 5 1 4 1 5 2 4 2 5 3 5 5 6 1 4 1 5 2 4 2 5 3 ...
output:
YES YES YES YES YES NO YES NO NO YES YES NO NO NO NO NO NO YES NO NO NO NO YES NO NO NO NO NO NO NO YES YES NO YES YES NO NO NO NO NO NO NO NO NO YES NO NO NO YES NO NO NO NO NO NO NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO...
result:
wrong answer expected YES, found NO [39th token]