답안 #59888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59888 2018-07-23T08:35:44 Z tmwilliamlin168 007 (CEOI14_007) C++14
100 / 100
252 ms 17992 KB
#include <bits/stdc++.h>
using namespace std;

inline int in() {
	int result = 0;
	char ch = getchar_unlocked();
	while(true) {
		if(ch >= '0' && ch <= '9')
			break;
		ch = getchar_unlocked();
	}
	result = ch-'0';
	while(true) {
		ch = getchar_unlocked();
		if (ch < '0' || ch > '9')
			break;
		result = result*10 + (ch - '0');
	}
	return result;
}
inline void out(int x) {
	if(!x) {
		putchar_unlocked('0');
		return;
	}
	if(x<0) {
		putchar_unlocked('-');
		x=-x;
	}
	int rev=x, c=0;
	while(!(rev%10)) {
		++c;
		rev/=10;
	}
	rev=0;
	while(x) {
		rev=rev*10+x%10;
		x/=10;
	}
	while(rev) {
		putchar_unlocked(rev%10+'0');
		rev/=10;
	}
	while(c--)
		putchar_unlocked('0');
}

const int mxN=2e5;
int n, m, s, d, a, b, da[mxN], db[mxN], qu[mxN], qh, qt, dp[mxN];
vector<int> adj[mxN];

inline void bfs(int s, int dist[mxN]) {
	qh=qt=0;
	memset(dist, 0x3F, 4*n);
	qu[qt++]=s;
	dist[s]=0;
	while(qh<qt) {
		int u=qu[qh++];
		for(int v : adj[u]) {
			if(dist[v]>n) {
				qu[qt++]=v;
				dist[v]=dist[u]+1;
			}
		}
	}
}

int cdp(int u) {
	if(!dp[u]) {
		dp[u]=da[u];
		for(int v : adj[u])
			if(da[v]==da[u]-1&&da[v]==db[v])
				dp[u]=min(cdp(v), dp[u]);
	}
	return dp[u];
}

int main() {
	n=in(), m=in(), s=in()-1, d=in()-1, a=in()-1, b=in()-1;
	while(m--) {
		int u=in()-1, v=in()-1;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	bfs(a, da);
	bfs(b, db);
	if(da[s]!=db[s]||da[d]!=db[d])
		out(max(min(da[d]-da[s], db[d]-db[s]), -1));
	else
		out(max(da[d]-da[s]-(cdp(d)<cdp(s)), -1));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 8 ms 5144 KB Output is correct
4 Correct 7 ms 5192 KB Output is correct
5 Correct 8 ms 5252 KB Output is correct
6 Correct 7 ms 5300 KB Output is correct
7 Correct 7 ms 5300 KB Output is correct
8 Correct 6 ms 5300 KB Output is correct
9 Correct 6 ms 5308 KB Output is correct
10 Correct 9 ms 5308 KB Output is correct
11 Correct 8 ms 5308 KB Output is correct
12 Correct 7 ms 5308 KB Output is correct
13 Correct 7 ms 5308 KB Output is correct
14 Correct 9 ms 5308 KB Output is correct
15 Correct 7 ms 5308 KB Output is correct
16 Correct 8 ms 5372 KB Output is correct
17 Correct 8 ms 5372 KB Output is correct
18 Correct 9 ms 5372 KB Output is correct
19 Correct 7 ms 5392 KB Output is correct
20 Correct 7 ms 5392 KB Output is correct
21 Correct 7 ms 5392 KB Output is correct
22 Correct 6 ms 5392 KB Output is correct
23 Correct 7 ms 5392 KB Output is correct
24 Correct 7 ms 5392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 7144 KB Output is correct
2 Correct 54 ms 8168 KB Output is correct
3 Correct 36 ms 8168 KB Output is correct
4 Correct 47 ms 8300 KB Output is correct
5 Correct 25 ms 8300 KB Output is correct
6 Correct 29 ms 8300 KB Output is correct
7 Correct 27 ms 8300 KB Output is correct
8 Correct 31 ms 8300 KB Output is correct
9 Correct 37 ms 8300 KB Output is correct
10 Correct 121 ms 12380 KB Output is correct
11 Correct 53 ms 12380 KB Output is correct
12 Correct 86 ms 12380 KB Output is correct
13 Correct 74 ms 12380 KB Output is correct
14 Correct 53 ms 12380 KB Output is correct
15 Correct 67 ms 12380 KB Output is correct
16 Correct 65 ms 12380 KB Output is correct
17 Correct 65 ms 12380 KB Output is correct
18 Correct 58 ms 12380 KB Output is correct
19 Correct 103 ms 12380 KB Output is correct
20 Correct 174 ms 14716 KB Output is correct
21 Correct 122 ms 14716 KB Output is correct
22 Correct 91 ms 14716 KB Output is correct
23 Correct 92 ms 14716 KB Output is correct
24 Correct 143 ms 14716 KB Output is correct
25 Correct 125 ms 14716 KB Output is correct
26 Correct 82 ms 14716 KB Output is correct
27 Correct 112 ms 14716 KB Output is correct
28 Correct 182 ms 14716 KB Output is correct
29 Correct 184 ms 14716 KB Output is correct
30 Correct 180 ms 15272 KB Output is correct
31 Correct 113 ms 15272 KB Output is correct
32 Correct 161 ms 15272 KB Output is correct
33 Correct 101 ms 15272 KB Output is correct
34 Correct 131 ms 15272 KB Output is correct
35 Correct 117 ms 15272 KB Output is correct
36 Correct 129 ms 15272 KB Output is correct
37 Correct 178 ms 15272 KB Output is correct
38 Correct 147 ms 15272 KB Output is correct
39 Correct 163 ms 15272 KB Output is correct
40 Correct 216 ms 15908 KB Output is correct
41 Correct 252 ms 17992 KB Output is correct