QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84567#4511. Wonderland ChaseBooksnow0 1677ms22668kbC++142.2kb2023-03-06 15:55:502023-03-06 15:55:53

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 15:55:53]
  • 评测
  • 测评结果:0
  • 用时:1677ms
  • 内存:22668kb
  • [2023-03-06 15:55:50]
  • 提交

answer

#include <bits/stdc++.h>
#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
//#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long 
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 1e5 + 10;
inline int read()
{
	
  int s = 0, w = 1;
  char ch = getchar();
  while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int T, n, m, A, Q, ans;
int st, ed, q[N], dir[N], dis[2][N];
bool vis[N], chk[N]; //是否是安全点 
vector<int> G[N];
inline void BFS(int s, int op)
{
	for(re int i = 1; i <= n; i++) dis[op][i] = -1;
	dis[op][s] = 0, st = 1, ed = 0, q[++ed] = s;
	while(st <= ed){
		int u = q[st]; st++;
		for(re int to : G[u])
			if(dis[op][to] == -1) dis[op][to] = dis[op][u] + 1, q[++ed] = to;
	}
}
inline void DFS(int u)
{
	chk[u] = true;
	if(G[u].size() == 1) ans = max(ans, dis[1][u]); //找到一个叶子然后不动 
	for(re int to : G[u])
		if(to != Q && !chk[to] && !vis[to]) DFS(to); 
}
inline void Sol(int Cas)
{
	n = read(), m = read(), A = read(), Q = read();
	if(Cas == 11) cout << n << " " << m << " " << A << " " << Q << "\n";
	for(re int i = 1; i <= n; i++) G[i].clear(), vis[i] = true, chk[i] = false, dir[i] = 0; 
	for(re int i = 1, x, y; i <= m; i++){
		x = read(), y = read(), G[x].pb(y), G[y].pb(x), dir[x]++, dir[y]++;
		if(Cas == 11) cout << x << " " << y << "\n";
	}
	st = 1, ed = 0;
	for(re int i = 1; i <= n; i++) if(dir[i] == 1) q[++ed] = i;
	while(st <= ed){
		int u = q[st];
		st++, vis[u] = false;
		for(re int to : G[u]){
			if(!vis[to]) continue;
			dir[to] -= 1;
			if(dir[to] == 1) q[++ed] = to;
		}
	}
	BFS(A, 0), BFS(Q, 1);
	if(dis[0][Q] == -1) { printf("Case #%d: SAFE\n", Cas); return; } //不在一个联通块 
	for(re int i = 1; i <= n; i++)
		if(vis[i] && dis[0][i] < dis[1][i]) { printf("Case #%d: SAFE\n", Cas); return; }
	ans = 0, DFS(A);
	//printf("Case #%d: %d\n", Cas, 2 * ans);
}
signed main()
{
	T = read();
	for(re int Cas = 1; Cas <= T; Cas++) Sol(Cas);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 7404kb

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 #2: SAFE
Case #5: SAFE
Case #6: SAFE
Case #7: SAFE
Case #8: SAFE
Case #9: SAFE
5 4 5 2
1 4
4 5
2 4
1 3
Case #13: SAFE
Case #26: SAFE
Case #27: SAFE
Case #28: SAFE
Case #29: SAFE
Case #30: SAFE
Case #31: SAFE
Case #32: SAFE
Case #33: SAFE
Case #34: SAFE
Case #44: SAFE
Case #45: SAFE
Case #46: SA...

result:

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

Test #2:

score: 0
Wrong Answer
time: 1677ms
memory: 22668kb

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 #6: SAFE
50000 49999 36869 38739
20677 35326
7453 47835
12061 48322
20700 29334
26539 48467
6269 44227
1753 10855
3165 13308
3427 49492
25531 48343
20155 28436
313 16576
16574 34982
12841 14125
28758 41758
26362 45007
1827 46165
40661 40720
10612 31732
29888 30489
41...

result:

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