QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84674 | #4511. Wonderland Chase | JWRuixi | 0 | 932ms | 10600kb | C++20 | 3.2kb | 2023-03-06 16:46:00 | 2023-03-06 16:46:49 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#define LL long long
#define writesp(x) write(x), putchar(' ')
#define writeln(x) write(x), putchar('\n')
#define FileIO(ch) freopen(ch".in", "r", stdin), freopen(ch".out", "w", stdout)
using namespace std;
namespace IO {
char ibuf[(1 << 20) + 1], *iS, *iT;
#if ONLINE_JUDGE
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
#else
#define gh() getchar()
#endif
inline long long read() {
char ch = gh();
long long x = 0;
bool t = 0;
while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
return t ? ~(x - 1) : x;
}
template <typename _Tp>
inline void write(_Tp x) {
static char stk[64], *top = stk;
if (x < 0) {
x = ~(x - 1);
putchar('-');
}
do *top++ = x % 10, x /= 10;
while (x);
while (top != stk) putchar((*--top) | 48);
}
}
using IO::read;
using IO::write;
const int maxn(1e5 + 7), maxm(2e5 + 7);
int n, m, head[maxn], tot, dA[maxn], dB[maxn], sA, sB, deg[maxn];
struct edge {
int v, nxt;
} e[maxm << 1];
inline void add_edge (int u, int v) {
e[++tot] = {v, head[u]};
head[u] = tot;
}
namespace DSU {
int fa[maxn], sz[maxn];
inline void init () {
for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
}
inline int find (int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
inline void merge (int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
if (sz[x] > sz[y]) swap(x, y);
fa[x] = y, sz[y] += sz[x];
}
}
inline void bfs (int S, int *d) {
static queue<int> q;
static bool vis[maxn];
memset(vis, 0, sizeof(bool) * (n + 1));
q.push(S);
d[S] = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
if (vis[u]) continue;
vis[u] = 1;
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].v;
if (vis[v]) continue;
d[v] = d[u] + 1;
q.push(v);
}
}
}
inline void slv (int Case) {
n = read(), m = read(), sA = read(), sB = read(), tot = 0;
memset(head, 0, sizeof(int) * (n + 1));
memset(deg, 0, sizeof(int) * (n + 1));
DSU::init();
for (int i = 1, u, v; i <= m; i++) {
u = read(), v = read();
add_edge(u, v);
add_edge(v, u);
DSU::merge(u, v);
++deg[u], ++deg[v];
}
if (DSU::find(sA) != DSU::find(sB)) {
printf("Case #%d: SAFE\n", Case);
return;
}
bfs(sA, dA), bfs(sB, dB);
queue<int> q;
for (int i = 1; i <= n; i++) if (deg[i] == 1) q.push(i);
while (!q.empty()) {
int u = q.front(); q.pop();
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].v;
--deg[v];
if (deg[v] == 1) q.push(v);
}
}
for (int i = 1; i <= n; i++)
if (deg[i] > 1 && dA[i] < dB[i])
return printf("Case #%d: SAFE\n", Case), void();
int ans = 0;
for (int i = 1; i <= n; i++)
if (dA[i] < dB[i])
ans = max(ans, dB[i]);
printf("Case #%d: %d\n", Case, ans << 1);
}
int main() {
int T = read();
for (int i = 1; i <= T; i++) slv(i);
}
// I love WHQ!
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 7744kb
input:
100 2 1 1 2 1 2 3 3 1 2 1 3 1 2 2 3 6 6 5 1 1 4 5 6 3 4 3 6 2 3 1 2 6 6 2 4 4 5 1 4 2 3 2 5 1 6 5 6 6 6 2 3 1 3 3 4 2 6 2 5 4 5 1 5 6 5 5 3 2 5 3 4 1 2 3 6 4 6 6 5 1 6 1 4 1 2 5 6 3 5 2 4 30 29 11 5 9 21 25 28 14 20 13 30 21 28 5 18 5 23 8 22 10 30 4 8 7 24 16 26 13 26 12 18 22 23 11 16 3 11 2 17 1 ...
output:
Case #1: 2 Case #2: SAFE Case #3: 8 Case #4: 6 Case #5: SAFE Case #6: SAFE Case #7: SAFE Case #8: SAFE Case #9: SAFE Case #10: 8 Case #11: 4 Case #12: 6 Case #13: SAFE Case #14: 2 Case #15: 10 Case #16: 10 Case #17: 6 Case #18: 2 Case #19: 28 Case #20: 28 Case #21: 18 Case #22: 2 Case #23: 58 Case #...
result:
wrong answer 12th lines differ - expected: 'Case #12: 2', found: 'Case #12: 6'
Test #2:
score: 0
Wrong Answer
time: 932ms
memory: 10600kb
input:
100 100000 99999 32832 52005 67463 96972 10280 86580 12146 44520 41541 86634 46936 64223 22701 46291 9093 80967 52512 77386 51062 58931 2092 55026 2096 2384 85102 92986 39914 66949 33370 68952 41576 58836 27668 33997 5843 30705 44415 57721 15188 28706 23340 55082 20335 90872 16029 80328 4656 74633 8...
output:
Case #1: SAFE Case #2: SAFE Case #3: 8 Case #4: 4 Case #5: 8 Case #6: SAFE Case #7: 2 Case #8: 39998 Case #9: 39998 Case #10: 19192 Case #11: 2 Case #12: 99998 Case #13: 99998 Case #14: 16776 Case #15: 2 Case #16: 199998 Case #17: 199998 Case #18: 141806 Case #19: SAFE Case #20: SAFE Case #21: SAFE ...
result:
wrong answer 5th lines differ - expected: 'Case #5: 2', found: 'Case #5: 8'