QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#630622#5307. Subgraph IsomorphismxzinWA 161ms11280kbC++141.8kb2024-10-11 19:35:492024-10-11 19:35:49

Judging History

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

  • [2024-10-11 19:35:49]
  • 评测
  • 测评结果:WA
  • 用时:161ms
  • 内存:11280kb
  • [2024-10-11 19:35:49]
  • 提交

answer

#include <bits/stdc++.h>

#define N 201000
#define ull unsigned long long
using namespace std;

vector<int> vec[N];
const ull mask = std::mt19937_64(time(nullptr))();

int d[N], n, m;
int vis[N];
ull hs[N];
void topo() {
    queue<int> q;

    for(int i = 1;i <= n; i++) 
        if(d[i] == 1) q.push(i);
    while (!q.empty())
    {
        int p = q.front(); q.pop(); vis[p] = 1;
        for(int i = 0; i < vec[p].size(); i++) {
            int v = vec[p][i];
            d[v]--;
            if(d[i] == 1) q.push(v);
            
        }
    }
    
}

ull shift(ull x) {
  x ^= mask;
  x ^= x << 13;
  x ^= x >> 7;
  x ^= x << 17;
  x ^= mask;
  return x;
}


void getHash(int x, int p) {
  hs[x] = 1;
  for (int i = 0 ; i < vec[x].size(); i++) {
    int v = vec[x][i];
    if (v == p || vis[v] == 0) continue;
    
    getHash(i, x);
    hs[x] += shift(hs[v]);
  }
}

void sl() {
    cin>>n>>m;
    for(int i = 0; i <= n; i++) vec[i].clear(), hs[i] = 0, vis[i] = 0, d[i] = 0;
    map<pair<int, int>, bool> mp;
    int mm = m;
    for(int i = 1;i <= m; i++) {
        int u, v;
        cin>>u>>v;
        if(u > v) swap(u, v);
        if(mp[{u,v}]) {mm--; continue;}
        mp[{u,v}] = 1;
        vec[u].push_back(v);
        vec[v].push_back(u);
        d[u]++; d[v]++;
    }
    if(mm == n - 1) {
        cout<<"YES"<<endl;
        return;
    }
    if(mm > n) {
        cout<<"NO"<<endl;
        return;
    }
    int p = 0;
    topo();
    for(int i = 1;i <= n; i++) {
        if(vis[i] == 0) {
            getHash(i, 0);
            if(hs[p] != hs[i] && p != 0) {
                cout<<"NO"<<endl;
                return;
            }
            p = i;
        }
    }
    cout<<"YES"<<endl;
    return;
}
int main() {
    int T; cin>>T;
    while(T--) sl();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 10852kb

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: 161ms
memory: 11280kb

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
NO
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]