Submission #454713

# Submission time Handle Problem Language Result Execution time Memory
454713 2021-08-05T07:27:25 Z kingfran1907 007 (CEOI14_007) C++14
0 / 100
304 ms 23480 KB
#include <bits/stdc++.h>
#define X first
#define Y second
 
using namespace std;
typedef long long llint;
 
const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 18;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, m;
int s, d, a, b;
vector< int > graph[maxn];
int disa[maxn], disb[maxn];

void calc(int x, int dis[maxn]) {
	for (int i = 1; i <= n; i++) dis[i] = -1;
	
	queue< int > q;
	dis[x] = 0;
	q.push(x);
	
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		
		for (int tren : graph[x]) {
			if (dis[tren] == -1) {
				dis[tren] = dis[x] + 1;
				q.push(tren);
			}
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	scanf("%d%d%d%d", &s, &d, &a, &b);
	
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	calc(a, disa);
	calc(b, disb);
	
	int sol = inf;
	if (disa[s] <= disa[d]) sol = min(sol, disa[d] - disa[s]);
	if (disb[s] <= disb[d]) sol = min(sol, disb[d] - disb[s]);
	
	if (sol == inf) printf("-1\n");
	else printf("%d\n", sol);
	return 0;
}

Compilation message

007.cpp: In function 'int main()':
007.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
007.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d%d%d%d", &s, &d, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Incorrect 3 ms 4996 KB Output isn't correct
5 Incorrect 3 ms 4996 KB Output isn't correct
6 Correct 3 ms 5024 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Incorrect 3 ms 4940 KB Output isn't correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Incorrect 3 ms 4940 KB Output isn't correct
13 Correct 3 ms 4940 KB Output is correct
14 Incorrect 3 ms 4940 KB Output isn't correct
15 Correct 3 ms 4968 KB Output is correct
16 Incorrect 4 ms 4940 KB Output isn't correct
17 Incorrect 5 ms 4940 KB Output isn't correct
18 Incorrect 4 ms 4940 KB Output isn't correct
19 Correct 4 ms 5000 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 4 ms 5004 KB Output is correct
24 Incorrect 3 ms 5016 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 6976 KB Output is correct
2 Incorrect 31 ms 7948 KB Output isn't correct
3 Correct 25 ms 7176 KB Output is correct
4 Incorrect 36 ms 8040 KB Output isn't correct
5 Correct 25 ms 6972 KB Output is correct
6 Correct 26 ms 7256 KB Output is correct
7 Correct 31 ms 7372 KB Output is correct
8 Correct 27 ms 7440 KB Output is correct
9 Incorrect 50 ms 8312 KB Output isn't correct
10 Correct 147 ms 16708 KB Output is correct
11 Incorrect 51 ms 9600 KB Output isn't correct
12 Correct 77 ms 10772 KB Output is correct
13 Incorrect 67 ms 9916 KB Output isn't correct
14 Correct 43 ms 9172 KB Output is correct
15 Correct 64 ms 10864 KB Output is correct
16 Correct 78 ms 11328 KB Output is correct
17 Correct 63 ms 10500 KB Output is correct
18 Incorrect 62 ms 10512 KB Output isn't correct
19 Correct 101 ms 12900 KB Output is correct
20 Incorrect 186 ms 18680 KB Output isn't correct
21 Incorrect 118 ms 13184 KB Output isn't correct
22 Correct 85 ms 12108 KB Output is correct
23 Correct 102 ms 13168 KB Output is correct
24 Correct 98 ms 13040 KB Output is correct
25 Incorrect 111 ms 12580 KB Output isn't correct
26 Correct 95 ms 12256 KB Output is correct
27 Correct 102 ms 13252 KB Output is correct
28 Correct 126 ms 13252 KB Output is correct
29 Correct 162 ms 15128 KB Output is correct
30 Incorrect 226 ms 19596 KB Output isn't correct
31 Incorrect 135 ms 14456 KB Output isn't correct
32 Correct 116 ms 13256 KB Output is correct
33 Correct 110 ms 13508 KB Output is correct
34 Incorrect 122 ms 14020 KB Output isn't correct
35 Incorrect 128 ms 13480 KB Output isn't correct
36 Incorrect 124 ms 13748 KB Output isn't correct
37 Correct 132 ms 14972 KB Output is correct
38 Correct 119 ms 14780 KB Output is correct
39 Correct 166 ms 14848 KB Output is correct
40 Incorrect 192 ms 18420 KB Output isn't correct
41 Correct 304 ms 23480 KB Output is correct