Submission #82345

# Submission time Handle Problem Language Result Execution time Memory
82345 2018-10-30T07:54:17 Z combi1k1 007 (CEOI14_007) C++14
0 / 100
172 ms 22580 KB
#pragma GCC optimize "-O3"
#include<bits/stdc++.h>

using namespace std;

#define pb  push_back

const int   N   = 1e5 + 1;

vector<int> g[N];

int n, m;
int X, S, A, B;
int d[N];

int  bfs(int s) {
	queue<int>  q;
	for(int i = 1 ; i <= n ; ++i)
		d[i] = N;
	d[s] = 0;   q.push(s);
	
	while(q.size()) {
		int u = q.front();  q.pop();
		for(int v : g[u])
			if (d[v] > d[u] + 1)    {
				d[v] = d[u] + 1;
				q.push(v);
			}
	}
	
	if (d[X] > d[S])    {
		puts("-1");
		exit(0);
	}
	
	return d[S] - d[X];
}

int main()  {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	//freopen("SPY.inp","r",stdin);
	//freopen("SPY.out","w",stdout);
	
	cin >> n >> m >> X >> S >> A >> B;
	
	while(m--)  {
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	
	cout << min(bfs(A),bfs(B));
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2816 KB Output is correct
3 Correct 4 ms 2816 KB Output is correct
4 Incorrect 4 ms 2856 KB Output isn't correct
5 Incorrect 4 ms 2860 KB Output isn't correct
6 Correct 5 ms 3012 KB Output is correct
7 Correct 4 ms 3060 KB Output is correct
8 Incorrect 4 ms 3060 KB Output isn't correct
9 Correct 4 ms 3060 KB Output is correct
10 Correct 4 ms 3060 KB Output is correct
11 Correct 4 ms 3060 KB Output is correct
12 Incorrect 5 ms 3060 KB Output isn't correct
13 Correct 4 ms 3060 KB Output is correct
14 Incorrect 4 ms 3060 KB Output isn't correct
15 Correct 4 ms 3060 KB Output is correct
16 Incorrect 4 ms 3060 KB Output isn't correct
17 Incorrect 4 ms 3068 KB Output isn't correct
18 Incorrect 5 ms 3092 KB Output isn't correct
19 Correct 4 ms 3116 KB Output is correct
20 Correct 5 ms 3124 KB Output is correct
21 Correct 5 ms 3276 KB Output is correct
22 Correct 5 ms 3276 KB Output is correct
23 Correct 5 ms 3276 KB Output is correct
24 Incorrect 5 ms 3276 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 5276 KB Output is correct
2 Incorrect 43 ms 6524 KB Output isn't correct
3 Correct 26 ms 6524 KB Output is correct
4 Incorrect 31 ms 7736 KB Output isn't correct
5 Correct 23 ms 7736 KB Output is correct
6 Correct 25 ms 8156 KB Output is correct
7 Correct 26 ms 8920 KB Output is correct
8 Correct 26 ms 9480 KB Output is correct
9 Incorrect 39 ms 10944 KB Output isn't correct
10 Correct 172 ms 20456 KB Output is correct
11 Incorrect 50 ms 20456 KB Output isn't correct
12 Runtime error 7 ms 20456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Incorrect 54 ms 22128 KB Output isn't correct
14 Correct 41 ms 22580 KB Output is correct
15 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 7 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 7 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 7 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 7 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 7 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 7 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 8 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 9 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 7 ms 22580 KB Execution killed with signal 11 (could be triggered by violating memory limits)