답안 #82383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82383 2018-10-30T11:18:40 Z atoiz 007 (CEOI14_007) C++14
10 / 100
268 ms 18408 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cassert>
#include <climits>
#include <fstream>
#include <stack>
#include <queue>
#include <map>

using namespace std;

const string FILE_NAME = "spy";
const string IN_FILE = FILE_NAME + ".inp";
const string OUT_FILE = FILE_NAME + ".out";

int readInt()
{
    char ch = getchar(); int ans = 0, sgn = 1;
    while (ch == ' ' || ch == '\n') ch = getchar();
    if (ch == '-') sgn = -1, ch = getchar();
    while (47 < ch && ch < 58) ans = ans * 10 + ch - 48, ch = getchar();
    return ans * sgn;
}

const int INF = 1e8;
const int MAX = 200010;
int n, m;
int s, d, a, b;
vector< vector<int> > dist(3, vector<int>(MAX, INF));
vector<int> deci(MAX, INF);
vector<int> gr[MAX];

int32_t main()
{

	n = readInt(); m = readInt();
	s = readInt(); d = readInt(); a = readInt(); b = readInt();
    for (int i = 0; i < m; ++i) {
		int u = readInt(), v = readInt();
        gr[u].push_back(v);
        gr[v].push_back(u);
    }


	dist[0][a] = 0;
	queue<int> qu; qu.push(a);
    while (!qu.empty()) {
        int u = qu.front(); qu.pop();
        for (int v : gr[u]) {
            if (dist[0][v] == INF) {
                dist[0][v] = dist[0][u] + 1;
                qu.push(v);
            }
        }
    }

	dist[1][b] = 0;
	assert(qu.empty());
	qu.push(b);
    while (!qu.empty()) {
        int u = qu.front(); qu.pop();
        for (int v : gr[u]) {
            if (dist[1][v] == INF) {
                dist[1][v] = dist[1][u] + 1;
                qu.push(v);
            }
        }
    }

	dist[2][d] = 0;
	assert(qu.empty());
	qu.push(d);
    while (!qu.empty()) {
        int u = qu.front(); qu.pop();
        for (int v : gr[u]) {
            if (dist[2][v] == INF) {
                dist[2][v] = dist[2][u] + 1;
                qu.push(v);
            }
        }
    }

    for (int u = 1; u <= n; ++u) {
        deci[u] = min(dist[0][u], dist[1][u]);
        for (int v : gr[u]) {
            if (dist[0][v] + 1 == dist[0][u] && dist[1][v] + 1 == dist[1][u]) {
                deci[u] = min(deci[u], deci[v]);
            }
        }
    }

	int ans = INF;
	for (int u = 1; u <= n; ++u) {
        bool block;
        if (dist[0][s] > dist[0][u]) block = 0;
        else if (dist[1][s] > dist[1][u]) block = 0;
        else if (dist[0][s] < dist[0][u]) block = 1;
        else if (dist[1][s] < dist[1][u]) block = 1;
        else if (deci[s] <= deci[u]) block = 1;
        else block = 0;

        if (u == d && (!block)) {
            cout << -1;
            return 0;
        }
        if (!block) {
            ans = min(ans, dist[2][u] - 1);
        }
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8168 KB Output is correct
2 Partially correct 10 ms 8168 KB Partially correct
3 Partially correct 9 ms 8208 KB Partially correct
4 Incorrect 9 ms 8372 KB Output isn't correct
5 Incorrect 9 ms 8372 KB Output isn't correct
6 Correct 12 ms 8372 KB Output is correct
7 Correct 12 ms 8372 KB Output is correct
8 Incorrect 9 ms 8372 KB Output isn't correct
9 Correct 10 ms 8372 KB Output is correct
10 Correct 9 ms 8372 KB Output is correct
11 Correct 9 ms 8372 KB Output is correct
12 Incorrect 9 ms 8372 KB Output isn't correct
13 Partially correct 9 ms 8372 KB Partially correct
14 Incorrect 9 ms 8372 KB Output isn't correct
15 Correct 9 ms 8372 KB Output is correct
16 Incorrect 9 ms 8372 KB Output isn't correct
17 Correct 9 ms 8372 KB Output is correct
18 Correct 9 ms 8476 KB Output is correct
19 Partially correct 10 ms 8476 KB Partially correct
20 Partially correct 9 ms 8476 KB Partially correct
21 Correct 9 ms 8476 KB Output is correct
22 Correct 9 ms 8476 KB Output is correct
23 Correct 14 ms 8476 KB Output is correct
24 Correct 10 ms 8476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 27 ms 9704 KB Partially correct
2 Correct 33 ms 10220 KB Output is correct
3 Correct 34 ms 10220 KB Output is correct
4 Correct 34 ms 10348 KB Output is correct
5 Correct 27 ms 10348 KB Output is correct
6 Correct 28 ms 10348 KB Output is correct
7 Correct 31 ms 10348 KB Output is correct
8 Correct 30 ms 10348 KB Output is correct
9 Correct 41 ms 10348 KB Output is correct
10 Partially correct 133 ms 14572 KB Partially correct
11 Correct 62 ms 14572 KB Output is correct
12 Partially correct 70 ms 14572 KB Partially correct
13 Incorrect 59 ms 14572 KB Output isn't correct
14 Correct 51 ms 14572 KB Output is correct
15 Correct 60 ms 14572 KB Output is correct
16 Correct 64 ms 14572 KB Output is correct
17 Correct 56 ms 14572 KB Output is correct
18 Correct 62 ms 14572 KB Output is correct
19 Partially correct 95 ms 14572 KB Partially correct
20 Correct 174 ms 15716 KB Output is correct
21 Incorrect 97 ms 15716 KB Output isn't correct
22 Partially correct 89 ms 15716 KB Partially correct
23 Correct 109 ms 15716 KB Output is correct
24 Correct 103 ms 15716 KB Output is correct
25 Correct 81 ms 15716 KB Output is correct
26 Partially correct 74 ms 15716 KB Partially correct
27 Correct 101 ms 15716 KB Output is correct
28 Correct 109 ms 15716 KB Output is correct
29 Partially correct 131 ms 15716 KB Partially correct
30 Correct 205 ms 16232 KB Output is correct
31 Incorrect 142 ms 16232 KB Output isn't correct
32 Correct 112 ms 16232 KB Output is correct
33 Correct 100 ms 16232 KB Output is correct
34 Correct 178 ms 16232 KB Output is correct
35 Incorrect 101 ms 16232 KB Output isn't correct
36 Correct 131 ms 16232 KB Output is correct
37 Correct 117 ms 16232 KB Output is correct
38 Correct 126 ms 16232 KB Output is correct
39 Correct 162 ms 16232 KB Output is correct
40 Correct 202 ms 16232 KB Output is correct
41 Partially correct 268 ms 18408 KB Partially correct