Submission #110519

# Submission time Handle Problem Language Result Execution time Memory
110519 2019-05-11T05:32:00 Z ckodser 007 (CEOI14_007) C++14
100 / 100
534 ms 23556 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 200005;
int n, m, a, b, s1, s2, D[2][N], F[N], P[N];
vector < int > vec[N], Adj[N];
inline void BFS(int st, int w, int tp = 0)
{
	queue < int > qu;
	qu.push(st); D[w][st] = 0;
	while (qu.size())
	{
		int v = qu.front();
		qu.pop();
		if (tp) vec[D[w][v]].pb(v);
		for (int &u : Adj[v])
			if (D[w][u] == -1)
				D[w][u] = D[w][v] + 1, qu.push(u);
	}
}
inline bool Check(int s, int t)
{
	if (D[0][t] < D[0][s] || D[1][t] < D[1][s])
		return 0;
	if (D[0][s] < D[0][t] || D[1][s] < D[1][t])
		return 1;
	return (F[s] <= F[t]);
}
inline bool CMP(int i, int j)
{
	return (D[0][i] < D[0][j]);
}
int main()
{
	scanf("%d%d%d%d%d%d", &n, &m, &s1, &s2, &a, &b);
	for (int i = 0; i < m; i++)
	{
		int v, u;
		scanf("%d%d", &v, &u);
		Adj[v].pb(u);
		Adj[u].pb(v);
	}
	memset(D, -1, sizeof(D));
	BFS(s2, 0, 1);
	memset(D, -1, sizeof(D));
	BFS(a, 0); BFS(b, 1);
	memset(F, 63, sizeof(F));
	for (int i = 1; i <= n; i++)
		P[i] = i;
	sort(P + 1, P + n + 1, CMP);
	for (int i = 1; i <= n; i++)
	{
		int v = P[i];
		if (D[0][v] == D[1][v])
		{
			F[v] = D[0][v];
			for (int u : Adj[v])
				if (D[0][v] == D[0][u] + 1 && D[1][v] == D[1][u] + 1)
					F[v] = min(F[v], F[u]);
		}
	}
	for (int i = 0; ; i ++)
		for (int v : vec[i])
			if (!Check(s1, v))
				return !printf("%d\n", i - 1);
	return 0;
}

Compilation message

007.cpp: In function 'int main()':
007.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d%d%d", &n, &m, &s1, &s2, &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &v, &u);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 16 ms 12032 KB Output is correct
4 Correct 12 ms 12032 KB Output is correct
5 Correct 13 ms 12032 KB Output is correct
6 Correct 15 ms 12104 KB Output is correct
7 Correct 12 ms 12032 KB Output is correct
8 Correct 13 ms 12032 KB Output is correct
9 Correct 14 ms 12132 KB Output is correct
10 Correct 15 ms 12024 KB Output is correct
11 Correct 13 ms 12004 KB Output is correct
12 Correct 15 ms 12160 KB Output is correct
13 Correct 14 ms 12032 KB Output is correct
14 Correct 13 ms 12160 KB Output is correct
15 Correct 13 ms 12124 KB Output is correct
16 Correct 15 ms 12160 KB Output is correct
17 Correct 14 ms 12032 KB Output is correct
18 Correct 14 ms 12160 KB Output is correct
19 Correct 14 ms 12032 KB Output is correct
20 Correct 16 ms 12032 KB Output is correct
21 Correct 14 ms 12132 KB Output is correct
22 Correct 13 ms 12032 KB Output is correct
23 Correct 14 ms 12236 KB Output is correct
24 Correct 14 ms 12160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 13916 KB Output is correct
2 Correct 61 ms 14584 KB Output is correct
3 Correct 44 ms 13816 KB Output is correct
4 Correct 60 ms 14712 KB Output is correct
5 Correct 44 ms 13688 KB Output is correct
6 Correct 73 ms 14072 KB Output is correct
7 Correct 56 ms 14072 KB Output is correct
8 Correct 69 ms 14044 KB Output is correct
9 Correct 79 ms 14516 KB Output is correct
10 Correct 264 ms 18808 KB Output is correct
11 Correct 151 ms 15736 KB Output is correct
12 Correct 138 ms 16760 KB Output is correct
13 Correct 114 ms 16220 KB Output is correct
14 Correct 120 ms 15464 KB Output is correct
15 Correct 136 ms 16840 KB Output is correct
16 Correct 131 ms 17076 KB Output is correct
17 Correct 144 ms 16724 KB Output is correct
18 Correct 142 ms 16544 KB Output is correct
19 Correct 204 ms 18148 KB Output is correct
20 Correct 297 ms 20600 KB Output is correct
21 Correct 214 ms 19064 KB Output is correct
22 Correct 194 ms 17756 KB Output is correct
23 Correct 219 ms 18812 KB Output is correct
24 Correct 183 ms 18808 KB Output is correct
25 Correct 181 ms 18168 KB Output is correct
26 Correct 179 ms 17928 KB Output is correct
27 Correct 175 ms 18732 KB Output is correct
28 Correct 176 ms 18564 KB Output is correct
29 Correct 237 ms 19708 KB Output is correct
30 Correct 368 ms 21232 KB Output is correct
31 Correct 228 ms 20088 KB Output is correct
32 Correct 225 ms 18680 KB Output is correct
33 Correct 208 ms 18808 KB Output is correct
34 Correct 238 ms 19192 KB Output is correct
35 Correct 216 ms 19320 KB Output is correct
36 Correct 211 ms 19960 KB Output is correct
37 Correct 229 ms 20216 KB Output is correct
38 Correct 240 ms 19960 KB Output is correct
39 Correct 270 ms 19836 KB Output is correct
40 Correct 299 ms 21692 KB Output is correct
41 Correct 534 ms 23556 KB Output is correct