QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252479 | #5307. Subgraph Isomorphism | ricofx | WA | 46ms | 6932kb | C++20 | 1.6kb | 2023-11-15 20:01:41 | 2023-11-15 20:01:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
#define hash miku
const int mod = 998244353;
const int N = 1e5 + 5;
int n, m, dfc, dfn[N], mark[N], faz[N];
vector<int> G[N], cyc;
ll h(ll x) {
return x * x * x * 1237123ull + 19260817ull;
}
ll f(ll x) {
ll cur = h(x & ((1ull << 31) - 1)) + h(x >> 31);
return cur;
}
ll hash(int u, int fa) {
ll res = 1;
for (int v : G[u]) if (v != fa && !mark[v]) {
res += f(hash(v, u));
}
return res;
}
void dfs(int u, int fa) {
dfn[u] = ++dfc;
faz[u] = fa;
for (int v : G[u]) if (v != fa) {
if (dfn[v] > dfn[u]) {
for (int x = v; ; x = faz[x]) {
cyc.push_back(x);
mark[x] = 1;
if (x == u) break;
}
} else if (!dfn[v]) dfs(v, u);
}
}
void solve() {
cin >> n >> m;
dfc = 0;
cyc.clear();
for (int i = 1; i <= n; i++) {
G[i].clear();
mark[i] = dfn[i] = faz[i] = 0;
}
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
if (m == n - 1) return cout << "YES\n", void();
if (m > n) return cout << "NO\n", void();
dfs(1, 1);
vector<ll> res;
for (int x : cyc) res.push_back(hash(x, x));
if (res == vector<ll>(res.size(), res[0])) {
cout << "YES\n";
} else {
bool ok = n % 2 == 0;
for (int i = 2; i < res.size(); i += 2) {
if (res[i] != res[0] || res[i + 1] != res[1]) ok = 0;
}
ok ? cout << "YES\n" : cout << "NO\n";
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5968kb
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: 0
Accepted
time: 35ms
memory: 5848kb
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 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:
ok 33192 token(s): yes count is 58, no count is 33134
Test #3:
score: 0
Accepted
time: 36ms
memory: 5956kb
input:
40000 9 24 1 4 1 6 1 7 1 9 2 5 2 7 2 8 2 9 3 5 3 7 3 8 3 9 4 6 4 8 4 9 5 6 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9 9 21 1 4 1 6 1 7 1 8 2 5 2 7 2 8 2 9 3 5 3 7 3 9 4 6 4 8 4 9 5 6 5 9 6 7 6 8 6 9 7 8 8 9 9 21 1 4 1 6 1 7 1 8 2 5 2 7 2 8 2 9 3 5 3 7 3 9 4 6 4 8 4 9 5 6 5 9 6 7 6 8 6 9 7 8 7 9 9 22 1 4 1 6 1 ...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 40000 token(s): yes count is 0, no count is 40000
Test #4:
score: 0
Accepted
time: 46ms
memory: 6932kb
input:
40000 9 16 1 4 1 6 1 8 1 9 2 5 2 7 2 8 2 9 3 6 3 7 4 7 5 8 6 9 7 8 7 9 8 9 9 16 1 4 1 6 1 8 1 9 2 5 2 7 2 8 2 9 3 6 3 7 4 7 5 8 5 9 7 8 7 9 8 9 9 16 1 4 1 6 1 8 1 9 2 5 2 7 2 8 2 9 3 6 3 7 4 7 5 8 5 9 6 9 7 8 8 9 9 16 1 4 1 6 1 8 1 9 2 5 2 7 2 8 2 9 3 6 3 7 4 7 5 8 5 9 6 9 7 8 7 9 9 17 1 4 1 6 1 8 1...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 40000 token(s): yes count is 0, no count is 40000
Test #5:
score: 0
Accepted
time: 45ms
memory: 5964kb
input:
40000 9 17 1 5 1 6 1 7 1 8 2 5 2 7 2 9 3 6 3 8 3 9 4 7 4 8 4 9 5 7 5 8 5 9 6 9 9 18 1 5 1 6 1 7 1 8 2 5 2 7 2 9 3 6 3 8 3 9 4 7 4 8 4 9 5 7 5 8 5 9 6 9 8 9 9 18 1 5 1 6 1 7 1 8 2 5 2 7 2 9 3 6 3 8 3 9 4 7 4 8 4 9 5 7 5 8 5 9 6 9 7 9 9 19 1 5 1 6 1 7 1 8 2 5 2 7 2 9 3 6 3 8 3 9 4 7 4 8 4 9 5 7 5 8 5 ...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 40000 token(s): yes count is 0, no count is 40000
Test #6:
score: 0
Accepted
time: 39ms
memory: 6180kb
input:
40000 9 17 1 5 1 6 1 7 1 8 2 6 2 7 2 8 2 9 3 7 3 9 4 9 5 8 6 7 6 8 6 9 7 9 8 9 9 16 1 5 1 6 1 7 1 8 2 6 2 7 2 8 2 9 3 7 3 9 4 9 5 8 5 9 6 7 6 8 8 9 9 16 1 5 1 6 1 7 1 8 2 6 2 7 2 8 2 9 3 7 3 9 4 9 5 8 5 9 6 7 6 8 7 9 9 17 1 5 1 6 1 7 1 8 2 6 2 7 2 8 2 9 3 7 3 9 4 9 5 8 5 9 6 7 6 8 7 9 8 9 9 17 1 5 1...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 40000 token(s): yes count is 0, no count is 40000
Test #7:
score: 0
Accepted
time: 44ms
memory: 6824kb
input:
40000 9 15 1 5 1 8 1 9 2 6 2 7 2 9 3 6 3 7 4 7 4 8 4 9 5 8 6 9 7 9 8 9 9 13 1 5 1 8 1 9 2 6 2 7 2 9 3 6 3 7 4 7 4 8 4 9 5 8 5 9 9 14 1 5 1 8 1 9 2 6 2 7 2 9 3 6 3 7 4 7 4 8 4 9 5 8 5 9 8 9 9 14 1 5 1 8 1 9 2 6 2 7 2 9 3 6 3 7 4 7 4 8 4 9 5 8 5 9 7 9 9 15 1 5 1 8 1 9 2 6 2 7 2 9 3 6 3 7 4 7 4 8 4 9 5...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok 40000 token(s): yes count is 1, no count is 39999
Test #8:
score: -100
Wrong Answer
time: 37ms
memory: 6140kb
input:
40000 9 8 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 8 1 8 1 9 2 9 3 9 4 9 5 9 6 9 7 9 9 9 1 8 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 8 1 8 2 8 3 9 4 9 5 9 6 9 7 9 8 9 9 8 1 8 1 9 2 8 3 9 4 9 5 9 6 9 7 9 9 9 1 8 1 9 2 8 3 9 4 9 5 9 6 9 7 9 8 9 9 9 1 8 1 9 2 8 2 9 3 9 4 9 5 9 6 9 7 9 9 10 1 8 1 9 2 8 2 9 3 9 4 9 5...
output:
YES YES NO YES YES NO NO NO YES YES NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO YES NO YES NO NO NO NO NO NO NO YES NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO YES NO NO NO N...
result:
wrong answer expected YES, found NO [673rd token]