답안 #243264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243264 2020-06-30T16:22:56 Z BamiTorabi 007 (CEOI14_007) C++14
0 / 100
313 ms 36432 KB
//Sasayego! Sasayego! Shinzou wo Sasageyo!

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x)  cerr << #x << " = " << x << endl
#define lid (id << 1)
#define rid (lid ^ 1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int dist[4][maxN];
queue <int> Q;
vector <int> G[maxN];

void BFS(int ix, int st){
	dist[ix][st] = 0;
	Q.push(st);
	while (!Q.empty()){
		int v = Q.front(); Q.pop();
		for (int u : G[v])
			if (dist[ix][u] > dist[ix][v] + 1){
				dist[ix][u] = dist[ix][v] + 1;
				Q.push(u);
			}
	}
	return;
}

int main(){
	time_t START = clock();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(dist, 63, sizeof dist);
	int n, m, s, t, a, b;
	cin >> n >> m >> s >> t >> a >> b;
	while (m--){
		int u, v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	BFS(0, s);
	BFS(1, t);
	BFS(2, a);
	BFS(3, b);
	if (dist[2][t] < dist[2][s] || dist[3][t] < dist[b][s])
		return cout << -1 << endl, 0;
	if (dist[2][t] - dist[2][s] != dist[3][t] - dist[3][s])
		return cout << min(dist[2][t] - dist[2][s], dist[3][t] - dist[3][s]) << endl, 0;
	int mns = n, mnt = n;
	for (int i = 1; i <= n; i++){
		if (dist[0][i] + dist[2][i] == dist[2][s] && dist[0][i] + dist[3][i] == dist[3][s])
			mns = min(mns, dist[2][i]);
		if (dist[1][i] + dist[2][i] == dist[2][t] && dist[1][i] + dist[3][i] == dist[3][t])
			mnt = min(mnt, dist[3][i]);
	}
	cout << dist[2][t] - dist[2][s] - (mnt > mns) << endl;
	time_t FINISH = clock();
	cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
	return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Correct 9 ms 8192 KB Output is correct
3 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 18 ms 16256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 18 ms 16512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 18 ms 16256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 19 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 19 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Incorrect 9 ms 8192 KB Output isn't correct
15 Runtime error 19 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 18 ms 16512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 19 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 18 ms 16512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 18 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 19 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 19 ms 16512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 41 ms 18936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 49 ms 20088 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 42 ms 19064 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 50 ms 20216 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 42 ms 18808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 40 ms 19192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 47 ms 19488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 44 ms 19448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 57 ms 20348 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 210 ms 29048 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 86 ms 22136 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 108 ms 23672 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 83 ms 22648 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Correct 57 ms 10744 KB Output is correct
15 Runtime error 100 ms 23672 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 131 ms 24056 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 92 ms 23288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 116 ms 23288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 147 ms 25720 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 230 ms 31288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 176 ms 26616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 158 ms 25404 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 129 ms 26488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 118 ms 26360 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 165 ms 25808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 141 ms 25336 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 147 ms 26488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 165 ms 26588 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 167 ms 28152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 226 ms 32380 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Runtime error 150 ms 28152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Runtime error 191 ms 26464 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Runtime error 145 ms 26840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 169 ms 27256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 135 ms 26872 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 141 ms 27256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 225 ms 28732 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 182 ms 28408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 218 ms 28408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 228 ms 31736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 313 ms 36432 KB Execution killed with signal 11 (could be triggered by violating memory limits)