QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#69454#5307. Subgraph Isomorphismmagicduck#WA 62ms5724kbC++143.0kb2022-12-27 17:19:162023-10-15 17:23:37

Judging History

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

  • [2023-10-15 17:23:37]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:62ms
  • 内存:5724kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-27 17:19:17]
  • 评测
  • 测评结果:0
  • 用时:1598ms
  • 内存:10816kb
  • [2022-12-27 17:19:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &F) {
    int R = 1; F = 0; char CH = getchar();
    for(; !isdigit(CH); CH = getchar()) if(CH == '-') R = -1;
    for(; isdigit(CH); CH = getchar()) F = F * 10 + CH - 48;
    F *= R;
}
inline void file(string str) {
    freopen((str + ".in").c_str(), "r", stdin);
    freopen((str + ".out").c_str(), "w", stdout);
}
const int N = 1e5 + 10;
int fa[N], now, fst[N], nxt[N << 1], num[N << 1], siz[N], g[N], R, n, m;
void add(int u, int v) {
    nxt[++now] = fst[u], fst[u] = now, num[now] = v;
    nxt[++now] = fst[v], fst[v] = now, num[now] = u;
}
unsigned long long f[N], pw[N];
const unsigned long long A = 1e9 + 7, B = 19260817, C = 2006;
unsigned long long h(unsigned long long x) {
    return A * x * x * x + B * x + C;
}
unsigned long long suan(unsigned long long x) {
    return h(x & ((1ull << 32) - 1)) + h(x >> 32);
}
void dfs(int x, int y) {
    f[x] = 1;
    for(int i = fst[x]; i; i = nxt[i]) {
        const int z = num[i];
        if(z == y) continue; dfs(z, x);
        f[x] += suan(f[z]);
    }
}
void calc(int x) {
    siz[x] = 1; g[x] = 0;
    for(int i = fst[x]; i; i = nxt[i]) {
        if(num[i] == fa[x]) continue;
        fa[num[i]] = x;
        calc(num[i]); siz[x] += siz[num[i]];
        g[x] = max(g[x], siz[num[i]]);
    }
    g[x] = max(g[x], n - siz[x]);
    if(g[x] < g[R]) R = x;
} 
int get_fa(int x) {
    return fa[x] == x ? x : fa[x] = get_fa(fa[x]);
}
pair<int, int> edge[N]; 
unsigned long long ran() {
    random_shuffle(edge + 1, edge + m + 1);
    for(int i = 1; i <= n + 1; i++) fst[i] = 0, fa[i] = i; now = 0;
    vector<pair<int, int> > e;
    for(int i = 1; i <= m; i++) {
        const int x = edge[i].first, y = edge[i].second;
        if(get_fa(x) == get_fa(y)) continue;
        e.emplace_back(x, y); add(x, y);
        fa[get_fa(x)] = get_fa(y);
    }
    fa[1] = R = 0; g[R] = 1e9;
    calc(1); int a = 0, b = 0, r = 0;
    if(g[R] == g[fa[R]]) a = R, b = fa[R], e.emplace_back(n + 1, a), e.emplace_back(n + 1, b), r = n + 1; else a = R, r = R;
    now = 0;
    for(int i = 1; i <= n + 1; i++) fst[i] = 0;
    for(auto i : e) {
        if((i.first == a && i.second == b) || (i.first == b && i.second == a)) continue;
        add(i.first, i.second);
    } 
    dfs(r, 0); return f[r];
}
int main() {
    //file("test");
    srand(time(0));
    int T; read(T);
    while(T--) {
        read(n), read(m);
        pw[0] = 1;
        for(int i = 1; i <= n + 1; i++) pw[i] = pw[i - 1] * B;
        for(int i = 1; i <= m; i++) read(edge[i].first), read(edge[i].second);
        unsigned long long G = ran(); int flag = 1;
        for(int i = 1; i <= 20; i++)
            if(ran() != G) {
                puts("NO"); flag = 0; break;
            }
        if(flag) puts("YES");
    }
    #ifdef _MagicDuck
        fprintf(stderr, "# Time: %.3lf s", (double)clock() / CLOCKS_PER_SEC);
    #endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5700kb

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: 62ms
memory: 5724kb

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
YES
NO
NO
NO
YES
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
N...

result:

wrong answer expected NO, found YES [43rd token]