QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624051 | #5307. Subgraph Isomorphism | 0x3fffffff | WA | 56ms | 3688kb | C++20 | 2.5kb | 2024-10-09 14:49:46 | 2024-10-09 14:49:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
using ULL = unsigned long long;
const ULL mask = mt19937_64(chrono::steady_clock::now().time_since_epoch().count())();
ULL shift(ULL x) {
x ^= mask;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
x ^= mask;
return x;
}
void solve() {
int n, m; cin >> n >> m;
vector<vector<int>>e(n + 1);
vector<int>in(n + 1);
for (int i = 1; i <= m; i++) {
int a, b; cin >> a >> b;
e[a].push_back(b);
e[b].push_back(a);
in[a]++; in[b]++;
}
if (m == n - 1) {
cout << "YES\n"; return;
}
if (m > n) {
cout << "NO\n"; return;
}
queue<int>q;
vector<int>vis(n + 1, 1);
for (int i = 1; i <= n; i++) {
if (in[i] == 1) {
q.push(i);
}
}
int cnt = n;
while (not q.empty()) {
int u = q.front();
q.pop();
vis[u] = 0; cnt--;
for (int v : e[u]) {
if (vis[v] and --in[v] == 1) {
q.push(v);
}
}
}
vector<ULL>h(n + 1);
auto get = [&](auto && get, int u, int fa)->void{
h[u] = 1;
for (int v : e[u]) {
if (v == fa || vis[v])continue;
get(get, v, u);
h[u] += shift(h[v]);
}
};
for (int i = 1; i <= n; i++) {
if (vis[i]) {
get(get, i, 0);
}
}
int su = 0, sv = 0;
for (int i = 1; i <= n; i++) {
if (vis[i]) {
for (int v : e[i]) {
if (vis[v]) {
su = i, sv = v;
break;
}
}
}
if (su)break;
}
vector<ULL>res;
auto dfs = [&](auto && ff, int u, int fa)->void{
res.push_back(h[u]);
for (int v : e[u]) {
if (v == fa || v == su)continue;
ff(ff, v, u);
}
};
dfs(dfs, su, sv);
if (cnt & 1) {
for (int i = 1; i < cnt; i++) {
if (res[i - 1] != res[i]) {
cout << "NO\n"; return;
}
}
} else {
for (int i = 2; i < cnt; i++) {
if (res[i - 2] != res[i]) {
cout << "NO\n"; return;
}
}
}
cout << "YES\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
cin >> tt;
while (tt--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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: 56ms
memory: 3688kb
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 NO 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 [60th token]