Submission #454802

# Submission time Handle Problem Language Result Execution time Memory
454802 2021-08-05T08:23:30 Z kingfran1907 007 (CEOI14_007) C++14
0 / 100
293 ms 16492 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 ax = disa[d] - disa[s];
	int bx = disb[d] - disb[s];
	if (ax > bx) swap(ax, bx);
	
	if (ax < 0 || bx < 0) printf("-1\n");
	else printf("%d\n", ax);
	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 4996 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Incorrect 3 ms 5000 KB Output isn't correct
5 Incorrect 3 ms 4996 KB Output isn't correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Incorrect 3 ms 4940 KB Output isn't correct
9 Correct 4 ms 4996 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Incorrect 3 ms 4904 KB Output isn't correct
13 Correct 3 ms 5000 KB Output is correct
14 Incorrect 3 ms 4972 KB Output isn't correct
15 Correct 3 ms 4940 KB Output is correct
16 Incorrect 3 ms 4940 KB Output isn't correct
17 Incorrect 3 ms 4940 KB Output isn't correct
18 Incorrect 3 ms 5164 KB Output isn't correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4996 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 4940 KB Output is correct
24 Incorrect 4 ms 5020 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 6744 KB Output is correct
2 Incorrect 31 ms 7508 KB Output isn't correct
3 Correct 24 ms 6904 KB Output is correct
4 Incorrect 32 ms 7568 KB Output isn't correct
5 Correct 23 ms 6776 KB Output is correct
6 Correct 28 ms 6944 KB Output is correct
7 Correct 26 ms 7180 KB Output is correct
8 Correct 34 ms 7100 KB Output is correct
9 Incorrect 41 ms 7492 KB Output isn't correct
10 Correct 152 ms 11792 KB Output is correct
11 Incorrect 56 ms 8784 KB Output isn't correct
12 Correct 88 ms 9668 KB Output is correct
13 Incorrect 57 ms 8964 KB Output isn't correct
14 Correct 46 ms 8448 KB Output is correct
15 Correct 62 ms 9648 KB Output is correct
16 Correct 88 ms 9924 KB Output is correct
17 Correct 62 ms 9504 KB Output is correct
18 Incorrect 64 ms 9512 KB Output isn't correct
19 Correct 97 ms 10692 KB Output is correct
20 Incorrect 197 ms 13424 KB Output isn't correct
21 Incorrect 95 ms 11444 KB Output isn't correct
22 Correct 83 ms 10612 KB Output is correct
23 Correct 102 ms 11332 KB Output is correct
24 Correct 90 ms 11452 KB Output is correct
25 Incorrect 85 ms 11032 KB Output isn't correct
26 Correct 91 ms 10748 KB Output is correct
27 Correct 98 ms 11468 KB Output is correct
28 Correct 103 ms 11400 KB Output is correct
29 Correct 162 ms 12016 KB Output is correct
30 Incorrect 210 ms 14020 KB Output isn't correct
31 Incorrect 104 ms 12372 KB Output isn't correct
32 Correct 99 ms 11332 KB Output is correct
33 Correct 125 ms 11680 KB Output is correct
34 Incorrect 149 ms 11900 KB Output isn't correct
35 Incorrect 108 ms 11708 KB Output isn't correct
36 Incorrect 126 ms 11960 KB Output isn't correct
37 Correct 134 ms 12772 KB Output is correct
38 Correct 158 ms 12620 KB Output is correct
39 Correct 138 ms 12712 KB Output is correct
40 Incorrect 217 ms 14240 KB Output isn't correct
41 Correct 293 ms 16492 KB Output is correct