QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#219636#5307. Subgraph IsomorphismisaunoyaWA 1ms5900kbC++232.2kb2023-10-19 16:56:582023-10-19 16:56:58

Judging History

你现在查看的是最新测评结果

  • [2023-10-19 16:56:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5900kb
  • [2023-10-19 16:56:58]
  • 提交

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;
}
int t=0;
void solve()
{
  t++;
  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(t==39) cout<<n<<","<<m,exit(0);
  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: 1ms
memory: 5836kb

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: 1ms
memory: 5900kb

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
6,6

result:

wrong output format YES or NO expected, but 6,6 found [39th token]