Submission #454728

# Submission time Handle Problem Language Result Execution time Memory
454728 2021-08-05T07:32:49 Z kingfran1907 007 (CEOI14_007) C++14
0 / 100
301 ms 16348 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 = min(disa[d] - disa[s], disb[d] - disb[s]);
	printf("%d\n", max(-1, 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 4 ms 4992 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Incorrect 3 ms 4992 KB Output isn't correct
5 Incorrect 3 ms 4940 KB Output isn't correct
6 Correct 3 ms 4940 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 4 ms 4940 KB Output is correct
14 Incorrect 3 ms 4940 KB Output isn't correct
15 Correct 3 ms 4940 KB Output is correct
16 Incorrect 4 ms 5004 KB Output isn't correct
17 Incorrect 3 ms 4940 KB Output isn't correct
18 Incorrect 3 ms 4940 KB Output isn't correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 3 ms 4964 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Incorrect 3 ms 4940 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6764 KB Output is correct
2 Incorrect 29 ms 7548 KB Output isn't correct
3 Correct 24 ms 6936 KB Output is correct
4 Incorrect 31 ms 7620 KB Output isn't correct
5 Correct 24 ms 6648 KB Output is correct
6 Correct 24 ms 6972 KB Output is correct
7 Correct 26 ms 7104 KB Output is correct
8 Correct 29 ms 7088 KB Output is correct
9 Incorrect 49 ms 7472 KB Output isn't correct
10 Correct 168 ms 11912 KB Output is correct
11 Incorrect 67 ms 8772 KB Output isn't correct
12 Correct 67 ms 9676 KB Output is correct
13 Incorrect 58 ms 9020 KB Output isn't correct
14 Correct 47 ms 8468 KB Output is correct
15 Correct 72 ms 9668 KB Output is correct
16 Correct 87 ms 9944 KB Output is correct
17 Correct 81 ms 9412 KB Output is correct
18 Incorrect 72 ms 9516 KB Output isn't correct
19 Correct 104 ms 10668 KB Output is correct
20 Incorrect 203 ms 13568 KB Output isn't correct
21 Incorrect 94 ms 11444 KB Output isn't correct
22 Correct 87 ms 10640 KB Output is correct
23 Correct 111 ms 11320 KB Output is correct
24 Correct 106 ms 11316 KB Output is correct
25 Incorrect 98 ms 10940 KB Output isn't correct
26 Correct 82 ms 10668 KB Output is correct
27 Correct 100 ms 11588 KB Output is correct
28 Correct 111 ms 11404 KB Output is correct
29 Correct 137 ms 12136 KB Output is correct
30 Incorrect 211 ms 14108 KB Output isn't correct
31 Incorrect 119 ms 12452 KB Output isn't correct
32 Correct 117 ms 11332 KB Output is correct
33 Correct 99 ms 11664 KB Output is correct
34 Incorrect 119 ms 12000 KB Output isn't correct
35 Incorrect 117 ms 11656 KB Output isn't correct
36 Incorrect 105 ms 11908 KB Output isn't correct
37 Correct 127 ms 12848 KB Output is correct
38 Correct 130 ms 12672 KB Output is correct
39 Correct 138 ms 12688 KB Output is correct
40 Incorrect 227 ms 14248 KB Output isn't correct
41 Correct 301 ms 16348 KB Output is correct