QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69468#5307. Subgraph Isomorphismmagicduck#WA 478ms7864kbC++142.7kb2022-12-27 17:42:102023-10-15 17:23:50

Judging History

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

  • [2023-10-15 17:23:50]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:478ms
  • 内存:7864kb
  • [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:42:12]
  • 评测
  • 测评结果:0
  • 用时:698ms
  • 内存:3880kb
  • [2022-12-27 17:42:10]
  • 提交

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], B;
const unsigned long long A = 1e9 + 9, C = 97; 
unsigned long long h(unsigned long long x) {
    return A * x * x * x + C;
}
unsigned long long suan(unsigned long long x) {
    return h(x & ((1ull << 32) - 1)) + h(x >> 32);
}
LL seed = chrono :: steady_clock :: now().time_since_epoch().count();
mt19937_64 rnd(seed);
void dfs(int x) {
    f[x] = B;
    for(int i = fst[x]; i; i = nxt[i]) {
        const int z = num[i];
        if(z == fa[x]) continue;
        fa[z] = x; dfs(z); f[x] += suan(f[z]);
    }
}
void calc(int x) {
    siz[x] = 1; g[x] = 0;
    for(int i = fst[x]; i; i = nxt[i]) {
        const int y = num[i];
        if(y == fa[x]) continue;
        fa[y] = x; calc(y); siz[x] += siz[y];
        g[x] = max(g[x], siz[y]);
    }
    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;
    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;
        add(x, y);
        fa[get_fa(x)] = get_fa(y);
    }
    fa[1] = R = 0; g[R] = 1e9; fa[n + 1] = 0;
    calc(1); if(g[R] == g[fa[R]]) fa[R] = n + 1, fa[n + 1] = R, R = n + 1;
    now = 0; memset(fst, 0, sizeof(fst));
    for(int i = 1; i <= n + 1; i++) if(fa[i]) add(i, fa[i]);
    fa[R] = 0; dfs(R); return f[R];
}
int main() {
    //file("test");
    srand(time(0));
    int T; read(T);
    while(T--) {
        read(n), read(m); B = rnd();
        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 <= 30; 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;
}

详细

Test #1:

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

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: 478ms
memory: 7864kb

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
YES
YES
NO
YES
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 YES, found NO [39th token]