QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84310#4511. Wonderland ChaseEnder32k0 527ms20784kbC++142.6kb2023-03-06 10:18:362023-03-06 10:19:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 10:19:46]
  • 评测
  • 测评结果:0
  • 用时:527ms
  • 内存:20784kb
  • [2023-03-06 10:18:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace vbzIO {
    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
    #define pc putchar
    #define pi pair<int, int>
    #define tu3 tuple<int, int, int>
    #define tu4 tuple<int, int, int, int>
    #define mp make_pair
    #define mt make_tuple
    #define fi first
    #define se second
    #define pb push_back
    #define ins insert
    #define era erase
    inline int read () {
        char ch = gh();
        int 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;
    }
    inline void write(int x) {
        if (x < 0) {
            x = ~(x - 1);
            putchar('-');
        }
        if (x > 9)
            write(x / 10);
        putchar(x % 10 + '0');
    }
}
using vbzIO::read;
using vbzIO::write;

const int maxn = 1e5 + 100;
int T, n, m, s, t, vis[maxn], dis[maxn][2], d[maxn];
vector<int> g[maxn];

void bfs(int x, int op) {
	queue<int> q;
	q.push(x), dis[x][op] = 0;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int v : g[u]) 
			if (dis[v][op] == 1e9) dis[v][op] = dis[u][op] + 1, q.push(v);
	}
}

void solve(int tp) {
	n = read(), m = read(), s = read(), t = read();
	for (int i = 1; i <= n; i++) d[i] = 0, g[i].clear();
	for (int i = 1, u, v; i <= m; i++) {
		u = read(), v = read();
		g[u].pb(v), g[v].pb(u), d[u]++, d[v]++;
	}
	queue<int> q;
	for (int i = 1; i <= n; i++) {
		vis[i] = (d[i] != 1), dis[i][0] = dis[i][1] = 1e9;
		if (!vis[i]) q.push(i);
	}
//	cerr << "!" << endl;
//	while (!q.empty()) {
//		int u = q.front(); q.pop();
//		for (int v : g[u]) {
//			d[v]--;
//			if (d[v] == 1 && vis[v]) q.push(v), vis[v] = 0; 
//		}
//	}
//	bfs(s, 0), bfs(t, 1);
//	for (int i = 1; i <= n; i++)
//		cerr << dis[i][0] << " " << dis[i][1] << endl;
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) continue;
//		cerr << i << endl;
		if (dis[i][0] < dis[i][1]) return printf("Case #%d: SAFE\n", tp), void();
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) 
		if (dis[i][0] < dis[i][1])
			ans = max(ans, dis[i][1]);
	if (ans == 1e9) return printf("Case #%d: SAFE\n", tp), void();
	printf("Case #%d: %d\n", tp, ans * 2);
}

int main() {
//	freopen("Q.in", "r", stdin);
	T = read();
	int tp = 0;
	while (T--) solve(++tp);
	return 0;
}
/*
1
6 5 1 6
1 4
1 2
5 6
3 5
2 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7432kb

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: 0
Case #2: 0
Case #3: 0
Case #4: 0
Case #5: 0
Case #6: 0
Case #7: 0
Case #8: 0
Case #9: 0
Case #10: 0
Case #11: 0
Case #12: 0
Case #13: 0
Case #14: 0
Case #15: 0
Case #16: 0
Case #17: 0
Case #18: 0
Case #19: 0
Case #20: 0
Case #21: 0
Case #22: 0
Case #23: 0
Case #24: 0
Case #25: 0
Case #26:...

result:

wrong answer 1st lines differ - expected: 'Case #1: 2', found: 'Case #1: 0'

Test #2:

score: 0
Wrong Answer
time: 527ms
memory: 20784kb

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: 0
Case #2: 0
Case #3: 0
Case #4: 0
Case #5: 0
Case #6: 0
Case #7: 0
Case #8: 0
Case #9: 0
Case #10: 0
Case #11: 0
Case #12: 0
Case #13: 0
Case #14: 0
Case #15: 0
Case #16: 0
Case #17: 0
Case #18: 0
Case #19: 0
Case #20: 0
Case #21: 0
Case #22: 0
Case #23: 0
Case #24: 0
Case #25: 0
Case #26:...

result:

wrong answer 1st lines differ - expected: 'Case #1: SAFE', found: 'Case #1: 0'