Submission #110735

# Submission time Handle Problem Language Result Execution time Memory
110735 2019-05-12T07:10:25 Z Mahdi_Jfri 007 (CEOI14_007) C++14
0 / 100
319 ms 20344 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back

const int maxn = 2e5 + 20;

vector<int> adj[maxn];

int d[2][maxn];

void bfs(int src , int k)
{
	memset(d[k] , 63  , sizeof d[k]);
	queue<int> q;
	q.push(src);
	d[k][src] = 0;

	while(!q.empty())
	{
		int v = q.front();
		q.pop();
		for(auto u : adj[v])
			if(d[k][u] > d[k][v] + 1)
			{
				d[k][u] = d[k][v] + 1;
				q.push(u);
			}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n , m;
	cin >> n >> m;

	int a , b , s , t;

	cin >> s >> t >> a >> b;
	s-- , t-- , a-- , b--;

	for(int i = 0; i < m; i++)
	{
		int a , b;
		cin >> a >> b;
		a-- , b--;

		adj[a].pb(b);
		adj[b].pb(a);
	}

	bfs(a , 0) , bfs(b , 1);

	if(d[0][s] > d[0][t] || d[1][s] > d[1][t])
		return cout << -1 << endl , 0;

	cout << min(d[0][t] - d[0][s] , d[1][t] - d[1][s]) << endl;
}
















# Verdict Execution time Memory Grader output
1 Correct 10 ms 6528 KB Output is correct
2 Correct 9 ms 6528 KB Output is correct
3 Correct 8 ms 6656 KB Output is correct
4 Incorrect 7 ms 6528 KB Output isn't correct
5 Incorrect 9 ms 6528 KB Output isn't correct
6 Correct 7 ms 6528 KB Output is correct
7 Correct 7 ms 6528 KB Output is correct
8 Incorrect 8 ms 6528 KB Output isn't correct
9 Correct 8 ms 6528 KB Output is correct
10 Correct 8 ms 6528 KB Output is correct
11 Correct 8 ms 6528 KB Output is correct
12 Incorrect 10 ms 6656 KB Output isn't correct
13 Correct 7 ms 6656 KB Output is correct
14 Incorrect 8 ms 6628 KB Output isn't correct
15 Correct 8 ms 6528 KB Output is correct
16 Incorrect 9 ms 6576 KB Output isn't correct
17 Incorrect 7 ms 6656 KB Output isn't correct
18 Incorrect 9 ms 6656 KB Output isn't correct
19 Correct 9 ms 6656 KB Output is correct
20 Correct 8 ms 6656 KB Output is correct
21 Correct 10 ms 6668 KB Output is correct
22 Correct 8 ms 6628 KB Output is correct
23 Correct 8 ms 6656 KB Output is correct
24 Incorrect 10 ms 6612 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 8324 KB Output is correct
2 Incorrect 50 ms 9180 KB Output isn't correct
3 Correct 36 ms 8496 KB Output is correct
4 Incorrect 64 ms 9208 KB Output isn't correct
5 Correct 32 ms 8312 KB Output is correct
6 Correct 34 ms 8696 KB Output is correct
7 Correct 32 ms 8704 KB Output is correct
8 Correct 39 ms 8672 KB Output is correct
9 Incorrect 49 ms 9592 KB Output isn't correct
10 Correct 187 ms 17016 KB Output is correct
11 Incorrect 82 ms 10488 KB Output isn't correct
12 Correct 79 ms 11648 KB Output is correct
13 Incorrect 80 ms 10904 KB Output isn't correct
14 Correct 50 ms 10104 KB Output is correct
15 Correct 76 ms 11640 KB Output is correct
16 Correct 121 ms 11896 KB Output is correct
17 Correct 95 ms 11228 KB Output is correct
18 Incorrect 98 ms 11404 KB Output isn't correct
19 Correct 127 ms 13688 KB Output is correct
20 Incorrect 273 ms 17948 KB Output isn't correct
21 Incorrect 118 ms 13688 KB Output isn't correct
22 Correct 103 ms 12664 KB Output is correct
23 Correct 121 ms 13420 KB Output is correct
24 Correct 125 ms 13432 KB Output is correct
25 Incorrect 111 ms 13048 KB Output isn't correct
26 Correct 116 ms 12668 KB Output is correct
27 Correct 124 ms 13616 KB Output is correct
28 Correct 147 ms 13560 KB Output is correct
29 Correct 178 ms 15668 KB Output is correct
30 Incorrect 237 ms 18424 KB Output isn't correct
31 Incorrect 139 ms 14736 KB Output isn't correct
32 Correct 128 ms 13632 KB Output is correct
33 Correct 129 ms 13880 KB Output is correct
34 Incorrect 134 ms 14200 KB Output isn't correct
35 Incorrect 114 ms 13816 KB Output isn't correct
36 Incorrect 125 ms 14092 KB Output isn't correct
37 Correct 149 ms 15224 KB Output is correct
38 Correct 166 ms 14888 KB Output is correct
39 Correct 174 ms 14940 KB Output is correct
40 Incorrect 252 ms 18224 KB Output isn't correct
41 Correct 319 ms 20344 KB Output is correct