QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#86737#4511. Wonderland Chaselnyx0 5235ms101324kbC++142.2kb2023-03-10 18:56:312023-03-10 18:56:32

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-10 18:56:32]
  • 评测
  • 测评结果:0
  • 用时:5235ms
  • 内存:101324kb
  • [2023-03-10 18:56:31]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

#define pb push_back

namespace IO {
	template<typename T> inline void rd(T &x) {
		x = 0; bool f = 0; char c = getchar();
		while (c < '0' || c > '9') f |= (c == '-'), c = getchar();
		while ('0' <= c && c <= '9') x = x * 10 + (c - '0'), c = getchar();
		x = f ? -x : x;
	}
	template<typename T, typename ...Args> inline void rd(T &x, Args& ...args) { rd(x), rd(args...); }
	template<typename T> inline void wt(T x, char c) {
		int stk[114], top = 0;
		if (x < 0) x = -x, putchar('-');
		do stk[ ++ top] = x % 10, x /= 10; while (x);
		while (top) putchar(stk[top -- ] + '0');
		putchar(c);
	}
}
using namespace IO;
using namespace std;

const int INF = 1e9;
const int N = 1e5 + 7;
vector<int> g[N];
int n, m, s, t;
int deg[N];
bool st[N];
int dist[N][2];

inline void bfs(int s, int x) {
	queue<int> q;
	q.push(s);
	dist[s][x] = 0;
	while (q.size()) {
		int u = q.front();
		q.pop();
		for (int v : g[u]) {
			if (dist[v][x] > dist[u][x] + 1) {
				dist[v][x] = dist[u][x] + 1;
				q.push(v);
			}
		}
	}
}

inline void solve() {
	rd(n, m, s, t);
	while (m -- ) {
		int u, v; rd(u, v);
		g[u].pb(v), g[v].pb(u);
		deg[u] ++ , deg[v] ++ ;
	}
	queue<int> q;
	for (int i = 1; i <= n; i ++ ) {
		if(deg[i] == 1) st[i] = 1, q.push(i);
	}
	while (q.size()) {
		int u = q.front();
		q.pop();
		for (int v : g[u]) {
			if (st[v]) continue;
			if (( -- deg[v]) == 1) st[v] = 1, q.push(v);
		}
	}
	for (int i = 1; i <= n; i ++ ) dist[i][0] = dist[i][1] = INF;
	bfs(s, 0), bfs(t, 1);
	bool flag = (dist[t][0] == INF);
	for (int u = 1; u <= n; u ++ ) {
		if (!st[u] && dist[u][0] < dist[u][1]) flag = 1;
	}
	if (flag) return puts("SAFE"), void();
	int res = 0;
	for (int u = 1; u <= n; u ++ ) {
		if (st[u] || dist[u][0] < dist[u][1] && dist[u][1] != INF) res = max(res, dist[u][1]); 
	}
	wt(res * 2, '\n');
	for (int i = 1; i <= n; i ++ ) g[i].clear(), deg[i] = 0, st[i] = 0;
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif
	int T; rd(T);
	for (int i = 1; i <= T; i ++ ) {
		printf("Case #%d: ", i);
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 6592kb

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: 6
Case #4: 6
Case #5: SAFE
Case #6: SAFE
Case #7: SAFE
Case #8: 18
Case #9: SAFE
Case #10: SAFE
Case #11: SAFE
Case #12: 8
Case #13: SAFE
Case #14: 8
Case #15: 10
Case #16: 10
Case #17: 6
Case #18: 18
Case #19: 28
Case #20: 28
Case #21: 18
Case #22: 22
Case #23: 58
...

result:

wrong answer 3rd lines differ - expected: 'Case #3: 8', found: 'Case #3: 6'

Test #2:

score: 0
Wrong Answer
time: 5235ms
memory: 101324kb

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: SAFE
Case #4: SAFE
Case #5: SAFE
Case #6: SAFE
Case #7: SAFE
Case #8: SAFE
Case #9: SAFE
Case #10: SAFE
Case #11: SAFE
Case #12: SAFE
Case #13: SAFE
Case #14: SAFE
Case #15: SAFE
Case #16: SAFE
Case #17: SAFE
Case #18: SAFE
Case #19: SAFE
Case #20: SAFE
Case #21:...

result:

wrong answer 3rd lines differ - expected: 'Case #3: 8', found: 'Case #3: SAFE'