답안 #455040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
455040 2021-08-05T11:48:36 Z kingfran1907 007 (CEOI14_007) C++14
0 / 100
301 ms 17688 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];
int dp[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);
			}
		}
	}
}

bool cmp(int a, int b) {
	return disa[a] < disa[b];
}

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);
	
	vector< int > v;
	for (int i = 1; i <= n; i++) v.push_back(i);
	sort(v.begin(), v.end(), cmp);
	
	for (int i : v) {
		dp[i] = 0;
		for (int tren : graph[i]) {
			if (disa[i] > disa[tren] && disb[i] > disb[tren]) dp[i] = max(dp[i], 1 + dp[tren]);
		}
	}
	
	if (disa[s] != disb[s] || disa[d] != disb[d]) {
		int sol = min(disa[d] - disa[s], disb[d] - disb[s]);
		printf("%d\n", max(sol, -1));
	} else {
		int sol = disa[d] - disa[s];
		if (dp[d] < dp[s]) sol--;
		printf("%d\n", max(sol, -1));
	}
	return 0;
}

Compilation message

007.cpp: In function 'int main()':
007.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
007.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d%d%d%d", &s, &d, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 4940 KB Output isn't correct
5 Incorrect 3 ms 4940 KB Output isn't correct
6 Correct 4 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 4 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 5008 KB Output is correct
14 Incorrect 3 ms 4940 KB Output isn't correct
15 Correct 4 ms 4940 KB Output is correct
16 Incorrect 4 ms 5068 KB Output isn't correct
17 Incorrect 4 ms 5000 KB Output isn't correct
18 Incorrect 4 ms 4940 KB Output isn't correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 5044 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Incorrect 4 ms 4940 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 6936 KB Output is correct
2 Incorrect 40 ms 7876 KB Output isn't correct
3 Correct 28 ms 7152 KB Output is correct
4 Incorrect 42 ms 7960 KB Output isn't correct
5 Correct 26 ms 6908 KB Output is correct
6 Correct 31 ms 7196 KB Output is correct
7 Correct 32 ms 7436 KB Output is correct
8 Partially correct 36 ms 7344 KB Partially correct
9 Incorrect 46 ms 7848 KB Output isn't correct
10 Correct 172 ms 12148 KB Output is correct
11 Incorrect 62 ms 9308 KB Output isn't correct
12 Correct 81 ms 10436 KB Output is correct
13 Incorrect 65 ms 9668 KB Output isn't correct
14 Correct 56 ms 8984 KB Output is correct
15 Correct 83 ms 10536 KB Output is correct
16 Correct 108 ms 10784 KB Output is correct
17 Correct 77 ms 10148 KB Output is correct
18 Incorrect 85 ms 10152 KB Output isn't correct
19 Correct 145 ms 11444 KB Output is correct
20 Incorrect 218 ms 14296 KB Output isn't correct
21 Incorrect 135 ms 12600 KB Output isn't correct
22 Correct 110 ms 11644 KB Output is correct
23 Correct 118 ms 12472 KB Output is correct
24 Correct 121 ms 12416 KB Output is correct
25 Incorrect 118 ms 12088 KB Output isn't correct
26 Correct 112 ms 11652 KB Output is correct
27 Correct 132 ms 12608 KB Output is correct
28 Partially correct 132 ms 12624 KB Partially correct
29 Correct 158 ms 13140 KB Output is correct
30 Incorrect 230 ms 15036 KB Output isn't correct
31 Incorrect 147 ms 13708 KB Output isn't correct
32 Correct 131 ms 12464 KB Output is correct
33 Correct 136 ms 12812 KB Output is correct
34 Incorrect 151 ms 13164 KB Output isn't correct
35 Incorrect 126 ms 12864 KB Output isn't correct
36 Incorrect 148 ms 13116 KB Output isn't correct
37 Correct 156 ms 14148 KB Output is correct
38 Correct 152 ms 13976 KB Output is correct
39 Correct 164 ms 14024 KB Output is correct
40 Incorrect 245 ms 15528 KB Output isn't correct
41 Correct 301 ms 17688 KB Output is correct