Submission #82366

# Submission time Handle Problem Language Result Execution time Memory
82366 2018-10-30T09:59:34 Z atoiz 007 (CEOI14_007) C++14
7 / 100
269 ms 18284 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[0][s] < dist[0][u]) block = 1;
        else if (dist[1][s] > dist[1][u]) block = 0;
        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;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8164 KB Output is correct
2 Partially correct 9 ms 8164 KB Partially correct
3 Partially correct 10 ms 8324 KB Partially correct
4 Incorrect 9 ms 8324 KB Output isn't correct
5 Incorrect 9 ms 8336 KB Output isn't correct
6 Correct 8 ms 8464 KB Output is correct
7 Correct 9 ms 8464 KB Output is correct
8 Incorrect 9 ms 8464 KB Output isn't correct
9 Correct 9 ms 8464 KB Output is correct
10 Correct 9 ms 8464 KB Output is correct
11 Correct 9 ms 8464 KB Output is correct
12 Incorrect 10 ms 8464 KB Output isn't correct
13 Partially correct 9 ms 8592 KB Partially correct
14 Incorrect 9 ms 8592 KB Output isn't correct
15 Correct 9 ms 8592 KB Output is correct
16 Incorrect 9 ms 8592 KB Output isn't correct
17 Correct 10 ms 8592 KB Output is correct
18 Correct 9 ms 8592 KB Output is correct
19 Partially correct 9 ms 8592 KB Partially correct
20 Partially correct 9 ms 8592 KB Partially correct
21 Incorrect 9 ms 8592 KB Output isn't correct
22 Correct 9 ms 8592 KB Output is correct
23 Correct 9 ms 8592 KB Output is correct
24 Correct 9 ms 8592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 27 ms 9708 KB Partially correct
2 Correct 33 ms 10220 KB Output is correct
3 Correct 29 ms 10220 KB Output is correct
4 Correct 34 ms 10344 KB Output is correct
5 Correct 28 ms 10344 KB Output is correct
6 Correct 27 ms 10344 KB Output is correct
7 Correct 32 ms 10344 KB Output is correct
8 Correct 46 ms 10344 KB Output is correct
9 Correct 46 ms 10348 KB Output is correct
10 Partially correct 140 ms 14568 KB Partially correct
11 Correct 55 ms 14568 KB Output is correct
12 Partially correct 70 ms 14568 KB Partially correct
13 Incorrect 59 ms 14568 KB Output isn't correct
14 Correct 60 ms 14568 KB Output is correct
15 Correct 66 ms 14568 KB Output is correct
16 Correct 81 ms 14568 KB Output is correct
17 Correct 73 ms 14568 KB Output is correct
18 Correct 97 ms 14568 KB Output is correct
19 Partially correct 99 ms 14568 KB Partially correct
20 Correct 199 ms 15908 KB Output is correct
21 Incorrect 107 ms 15908 KB Output isn't correct
22 Partially correct 126 ms 15908 KB Partially correct
23 Correct 126 ms 15908 KB Output is correct
24 Correct 111 ms 15908 KB Output is correct
25 Correct 124 ms 15908 KB Output is correct
26 Partially correct 102 ms 15908 KB Partially correct
27 Correct 92 ms 15908 KB Output is correct
28 Correct 135 ms 15908 KB Output is correct
29 Partially correct 198 ms 15908 KB Partially correct
30 Correct 212 ms 16232 KB Output is correct
31 Incorrect 110 ms 16232 KB Output isn't correct
32 Correct 110 ms 16232 KB Output is correct
33 Correct 110 ms 16232 KB Output is correct
34 Correct 135 ms 16232 KB Output is correct
35 Incorrect 96 ms 16232 KB Output isn't correct
36 Correct 132 ms 16232 KB Output is correct
37 Correct 122 ms 16232 KB Output is correct
38 Correct 132 ms 16232 KB Output is correct
39 Correct 163 ms 16232 KB Output is correct
40 Correct 233 ms 16232 KB Output is correct
41 Partially correct 269 ms 18284 KB Partially correct