답안 #112516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112516 2019-05-20T11:32:42 Z Kastanda 007 (CEOI14_007) C++11
100 / 100
430 ms 30788 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);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Correct 13 ms 12160 KB Output is correct
3 Correct 13 ms 12160 KB Output is correct
4 Correct 12 ms 12032 KB Output is correct
5 Correct 12 ms 12032 KB Output is correct
6 Correct 12 ms 12032 KB Output is correct
7 Correct 12 ms 12152 KB Output is correct
8 Correct 13 ms 12160 KB Output is correct
9 Correct 12 ms 12032 KB Output is correct
10 Correct 12 ms 12032 KB Output is correct
11 Correct 13 ms 12032 KB Output is correct
12 Correct 13 ms 12160 KB Output is correct
13 Correct 12 ms 12032 KB Output is correct
14 Correct 13 ms 12160 KB Output is correct
15 Correct 13 ms 12160 KB Output is correct
16 Correct 12 ms 12032 KB Output is correct
17 Correct 12 ms 12160 KB Output is correct
18 Correct 12 ms 12160 KB Output is correct
19 Correct 12 ms 12160 KB Output is correct
20 Correct 12 ms 12160 KB Output is correct
21 Correct 11 ms 12160 KB Output is correct
22 Correct 12 ms 12160 KB Output is correct
23 Correct 12 ms 12160 KB Output is correct
24 Correct 12 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 14376 KB Output is correct
2 Correct 53 ms 15228 KB Output is correct
3 Correct 43 ms 14356 KB Output is correct
4 Correct 55 ms 15480 KB Output is correct
5 Correct 38 ms 14172 KB Output is correct
6 Correct 46 ms 14584 KB Output is correct
7 Correct 46 ms 14840 KB Output is correct
8 Correct 45 ms 14584 KB Output is correct
9 Correct 62 ms 15480 KB Output is correct
10 Correct 194 ms 24056 KB Output is correct
11 Correct 81 ms 16924 KB Output is correct
12 Correct 106 ms 18356 KB Output is correct
13 Correct 87 ms 17272 KB Output is correct
14 Correct 75 ms 16504 KB Output is correct
15 Correct 104 ms 18168 KB Output is correct
16 Correct 115 ms 18552 KB Output is correct
17 Correct 101 ms 17820 KB Output is correct
18 Correct 103 ms 17836 KB Output is correct
19 Correct 176 ms 20572 KB Output is correct
20 Correct 307 ms 26084 KB Output is correct
21 Correct 174 ms 21112 KB Output is correct
22 Correct 142 ms 19576 KB Output is correct
23 Correct 337 ms 20768 KB Output is correct
24 Correct 163 ms 20724 KB Output is correct
25 Correct 171 ms 20060 KB Output is correct
26 Correct 153 ms 19660 KB Output is correct
27 Correct 163 ms 20728 KB Output is correct
28 Correct 166 ms 20600 KB Output is correct
29 Correct 221 ms 23024 KB Output is correct
30 Correct 353 ms 26952 KB Output is correct
31 Correct 199 ms 22552 KB Output is correct
32 Correct 179 ms 20600 KB Output is correct
33 Correct 156 ms 20972 KB Output is correct
34 Correct 197 ms 21468 KB Output is correct
35 Correct 165 ms 21240 KB Output is correct
36 Correct 183 ms 22132 KB Output is correct
37 Correct 203 ms 22564 KB Output is correct
38 Correct 202 ms 22264 KB Output is correct
39 Correct 224 ms 22136 KB Output is correct
40 Correct 301 ms 26396 KB Output is correct
41 Correct 430 ms 30788 KB Output is correct