Submission #110754

# Submission time Handle Problem Language Result Execution time Memory
110754 2019-05-12T07:49:41 Z Mahdi_Jfri 007 (CEOI14_007) C++14
27 / 100
417 ms 19692 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[3][maxn] , x[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) , bfs(t , 2);

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

	vector<pair<int , int> > tmp;
	for(int i = 0; i < n; i++)
		tmp.pb({d[0][i] , i});

	sort(tmp.begin() , tmp.end());
	reverse(tmp.begin() , tmp.end());

	for(auto sht : tmp)
	{
		int v = sht.second;

		x[v] = 0;
		for(auto u : adj[v])
			if(d[0][u] == d[0][v] + 1 && d[1][u] == d[1][v] + 1)
				x[v] = max(x[v] , x[u] + 1);
	}

	int res = 1e9;
	for(int t = 0; t < n; t++)
	{
		if(d[0][s] > d[0][t] || d[1][s] > d[1][t])
			res = min(res , d[2][t]);
		else if(d[0][s] == d[0][t] && d[1][s] == d[1][t] && x[t] > x[s])
			res = min(res , d[2][t]);
	}

	cout << res - 1 << endl;
}











# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Partially correct 9 ms 7424 KB Partially correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 8 ms 7424 KB Output is correct
7 Correct 9 ms 7500 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Partially correct 9 ms 7424 KB Partially correct
10 Correct 10 ms 7424 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 11 ms 7424 KB Output is correct
13 Partially correct 9 ms 7424 KB Partially correct
14 Incorrect 9 ms 7552 KB Output isn't correct
15 Partially correct 9 ms 7424 KB Partially correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 9 ms 7396 KB Output is correct
18 Correct 10 ms 7424 KB Output is correct
19 Partially correct 10 ms 7424 KB Partially correct
20 Partially correct 10 ms 7552 KB Partially correct
21 Correct 9 ms 7424 KB Output is correct
22 Correct 9 ms 7424 KB Output is correct
23 Correct 9 ms 7424 KB Output is correct
24 Correct 10 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 42 ms 9460 KB Partially correct
2 Correct 56 ms 10228 KB Output is correct
3 Partially correct 40 ms 9592 KB Partially correct
4 Correct 64 ms 10352 KB Output is correct
5 Correct 40 ms 9336 KB Output is correct
6 Correct 40 ms 9588 KB Output is correct
7 Correct 41 ms 9852 KB Output is correct
8 Correct 43 ms 9840 KB Output is correct
9 Correct 64 ms 10224 KB Output is correct
10 Partially correct 199 ms 14576 KB Partially correct
11 Correct 90 ms 11504 KB Output is correct
12 Partially correct 109 ms 12568 KB Partially correct
13 Correct 112 ms 11884 KB Output is correct
14 Correct 51 ms 10104 KB Output is correct
15 Partially correct 107 ms 12752 KB Partially correct
16 Correct 147 ms 12912 KB Output is correct
17 Correct 118 ms 12404 KB Output is correct
18 Correct 110 ms 12368 KB Output is correct
19 Partially correct 177 ms 13480 KB Partially correct
20 Correct 321 ms 16416 KB Output is correct
21 Correct 184 ms 14804 KB Output is correct
22 Partially correct 150 ms 14044 KB Partially correct
23 Partially correct 168 ms 14652 KB Partially correct
24 Partially correct 146 ms 14624 KB Partially correct
25 Correct 194 ms 14500 KB Output is correct
26 Partially correct 172 ms 14188 KB Partially correct
27 Correct 173 ms 14676 KB Output is correct
28 Correct 188 ms 14704 KB Output is correct
29 Partially correct 233 ms 15576 KB Partially correct
30 Correct 306 ms 17248 KB Output is correct
31 Correct 195 ms 15584 KB Output is correct
32 Partially correct 192 ms 14688 KB Partially correct
33 Partially correct 187 ms 14872 KB Partially correct
34 Correct 197 ms 15064 KB Output is correct
35 Correct 164 ms 14960 KB Output is correct
36 Correct 186 ms 15212 KB Output is correct
37 Correct 223 ms 15972 KB Output is correct
38 Correct 227 ms 15848 KB Output is correct
39 Correct 239 ms 15848 KB Output is correct
40 Correct 300 ms 17500 KB Output is correct
41 Partially correct 417 ms 19692 KB Partially correct