QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#219619#5307. Subgraph IsomorphismisaunoyaWA 65ms7156kbC++232.3kb2023-10-19 16:48:272023-10-19 16:48:29

Judging History

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

  • [2023-10-19 16:48:29]
  • 评测
  • 测评结果:WA
  • 用时:65ms
  • 内存:7156kb
  • [2023-10-19 16:48:27]
  • 提交

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 S=1;
unsigned long long shift(unsigned long long x)
{
  static const unsigned long long mask=std::chrono::steady_clock::now().time_since_epoch().count();
  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;
  map<pair<int,int>,bool>book;
  for(int i=1;i<=m;i++)
  {
    int x,y;
    cin>>x>>y;
    if(book.count({x,y})) continue;
    book[{x,y}]=true;
    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: 0ms
memory: 7156kb

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: 65ms
memory: 6784kb

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]