QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113378#4511. Wonderland Chaseatgc8 3ms11664kbC++141.8kb2023-06-17 12:18:412023-06-17 12:18:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-17 12:18:45]
  • 评测
  • 测评结果:8
  • 用时:3ms
  • 内存:11664kb
  • [2023-06-17 12:18:41]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5+10,maxm = 1e6+10;
struct {
	int nxt,v;
}edge[maxm];
int deg[maxn],T,n,m,a,b,ec,head[maxn];
set<int> tag[maxn]; 
inline void addedge(int u,int v) {
	++deg[u];
	edge[++ec] = {head[u],v};
	head[u] = ec;
}
inline void clearedge(){
	memset(head,0,n + 10 << 4);
	memset(deg,0,n + 10 << 4);
	ec = 0;
	for(int i = 1;i <= n;++i) tag[i].clear();
}
inline void toposort(){
	static queue<int> q;
	for(int i = 1;i <= n;++i) if(deg[i] == 1) q.push(i);
	while(!q.empty()) {
		const int u = q.front();q.pop();
		for(int i = head[u];i;i = edge[i].nxt) {
			const int v = edge[i].v;
			if(--deg[v] == 1) q.push(v);
		}
	}
}
#define pb push_back
#define pii pair<int,int>
vector<int> sf;
int da[maxn],db[maxn],*dis;
bool vis[maxn];
inline void dij(int s){
	memset(dis,0x3f,n + 10 << 4);
	memset(vis,0,n + 10 << 4);
	static priority_queue<pii,vector<pii>,greater<pii>> pq;
	pq.push({dis[s] = 0,s});
	while(!pq.empty()) {
		int du,u;
		tie(du,u) = pq.top(); pq.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		for(int i = head[u];i;i=edge[i].nxt) {
			const int v = edge[i].v;
			if(dis[v] >dis[u] + 1) pq.push({dis[v] = du+1,v});
		}
	}
}
signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin>>T;
	for(int cas = 1;cas <= T;++cas) {
		int ans = 0;
		cout<<"Case #"<<cas<<": ";
		cin>>n>>m>>a>>b;
		clearedge();
		for(int i = 1,u,v;i<=m;++i) {
			cin>>u>>v;
			if(u != v && !tag[u].count(v))
				addedge(u,v),addedge(v,u),tag[u].insert(v);
		}
		toposort();
		dis = da, dij(a);
		dis = db, dij(b);
		for(int u = 1;u <= n;++u) if(deg[u] > 1 && da[u] < db[u]) {
			cout<<"SAFE";
			goto sb;
		}
		for(int u = 1;u <= n;++u) if(da[u] < db[u]) ans = max(ans,db[u]);
		cout<<(ans > 2 * n ? "SAFE" : to_string(ans*2));
		sb: cout<<'\n'; 
	} 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 8
Accepted
time: 3ms
memory: 11664kb

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: 2
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:

ok 100 lines

Test #2:

score: 0
Dangerous Syscalls

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:


result: