QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279610 | #5307. Subgraph Isomorphism | zzuqy# | WA | 48ms | 6236kb | C++20 | 2.3kb | 2023-12-08 22:13:23 | 2023-12-08 22:13:24 |
Judging History
answer
#include <cmath>
#include <cctype>
#include <chrono>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;
const int N = 1e5 + 9;
typedef long long ll;
int read() {
int x = 0, s = 1; char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') s = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
return x * s;
}
#define ull unsigned long long
const ull mask = std::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;
}
ull H[N];
vector<int> edges[N];
int n, m, d[N], is_on_ring[N];
// std::set<ull> trees;
void getHash(int x, int p) {
H[x] = 1;
for (int i : edges[x]) {
if (i == p || is_on_ring[i])
continue;
getHash(i, x);
H[x] += shift(H[i]);
}
// trees.insert(H[x]);
}
void solve() {
cin >> n >> m;
// init
for (int i = 1; i <= n; ++i) {
edges[i].clear();
d[i] = 0;
// 环标记
is_on_ring[i] = 1; // 初始都在环上,找不在环上的
}
// solve
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
edges[u].push_back(v);
edges[v].push_back(u);
d[u]++;
d[v]++;
}
if (n - 1 == m) {
cout << "YES" << '\n';
return;
}
if (m > n) {
cout << "NO" << '\n';
return;
}
// 基环
queue<int> que;
for (int i = 1; i <= n; ++i) {
if (d[i] == 1) {
que.push(i);
}
}
while (que.size()) {
int u = que.front();
que.pop();
is_on_ring[u] = false;
for (int v : edges[u]) {
if (--d[v] == 1)
que.push(v);
}
}
ull hs = 0;
bool same = true;
int i;
for (i = 1; i <= n; ++i) {
if (is_on_ring[i]) {
getHash(i, 0);
hs = H[i];
break;
}
}
for (i = i + 1; i <= n; ++i) {
if (is_on_ring[i]) {
getHash(i, 0);
if (hs != H[i]) {
cout << "NO" << '\n';
return;
}
}
}
cout << "YES" << '\n';
}
int main() {
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6236kb
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: 48ms
memory: 6044kb
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]