Submission #981855

# Submission time Handle Problem Language Result Execution time Memory
981855 2024-05-13T15:47:53 Z vjudge1 Swapping Cities (APIO20_swap) C++17
37 / 100
2000 ms 35528 KB
#include "swap.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
long long n, m, i, j, sz[200001], p[200001], d[200001], mx[200001], szm[200001];
vector<pair<long long, long long>> g[200001];
vector<pair<long long, pair<long long, long long>>> gg;

long long get(long long x) {
	return x == p[x] ? x : p[x] = get(p[x]);
}

void merge(long long xx, long long yy) {
	long long x = get(xx), y = get(yy);
	mx[x] = max({mx[x], d[x], d[xx]});
	mx[y] = max({mx[y], d[y], d[yy]});
	mx[x] = max(mx[x], mx[y]);
	mx[y] = max(mx[y], mx[x]);
	szm[x]++;
	if (x == y) return;
	if (sz[x] < sz[y]) swap(x, y);
	p[y] = x;
	sz[x] += sz[y];
	szm[x] += szm[y];
	mx[x] = max(mx[x], mx[y]);
}

void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
	n = N, m = M;
	for (long long i = 0; i < M; i++) {
		g[U[i]].push_back({V[i], W[i]});
		g[V[i]].push_back({U[i], W[i]});
		gg.push_back({W[i], {U[i], V[i]}});
	}
	sort(gg.begin(), gg.end());
}

bool check(long long md, long long x, long long y) {
	if (md < 0 || md >= gg.size()) return 0;
	for (long long i = 0; i < n; i++) sz[i] = 1, p[i] = i, d[i] = mx[i] = szm[i] = 0;
	for (long long i = 0; i <= md; i++) {
		d[gg[i].second.first]++;
		d[gg[i].second.second]++;
		merge(gg[i].second.first, gg[i].second.second);
	}
	if (get(x) != get(y)) return 0;
	if (mx[get(x)] <= 2 && szm[get(x)] < sz[get(x)]) return 0;
	return 1;
}

int getMinimumFuelCapacity(int X, int Y) {
	long long l = 0, r = (int)gg.size(), md, ans = 0;
	while (l <= r) {
		md = (l + r) / 2;
		if (check(md, X, Y)) ans = md, r = md - 1;
		else l = md + 1;
	}
	if (!check(ans, X, Y)) return -1;
  return gg[ans].first;
}

Compilation message

swap.cpp: In function 'bool check(long long int, long long int, long long int)':
swap.cpp:40:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  if (md < 0 || md >= gg.size()) return 0;
      |                ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 13144 KB Output is correct
6 Correct 3 ms 12904 KB Output is correct
7 Correct 3 ms 13052 KB Output is correct
8 Correct 3 ms 12888 KB Output is correct
9 Correct 116 ms 21448 KB Output is correct
10 Correct 236 ms 23364 KB Output is correct
11 Correct 289 ms 23428 KB Output is correct
12 Correct 290 ms 23796 KB Output is correct
13 Correct 226 ms 24424 KB Output is correct
14 Execution timed out 2082 ms 22888 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Execution timed out 2029 ms 26764 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 13144 KB Output is correct
6 Correct 3 ms 12904 KB Output is correct
7 Correct 3 ms 13052 KB Output is correct
8 Correct 3 ms 12888 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Correct 3 ms 12888 KB Output is correct
11 Correct 3 ms 12892 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 4 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12892 KB Output is correct
20 Correct 3 ms 12892 KB Output is correct
21 Correct 3 ms 12892 KB Output is correct
22 Correct 4 ms 12888 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 4 ms 12892 KB Output is correct
25 Correct 4 ms 13148 KB Output is correct
26 Correct 4 ms 13148 KB Output is correct
27 Correct 3 ms 12892 KB Output is correct
28 Correct 4 ms 13152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 13144 KB Output is correct
7 Correct 3 ms 12904 KB Output is correct
8 Correct 3 ms 13052 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Correct 116 ms 21448 KB Output is correct
11 Correct 236 ms 23364 KB Output is correct
12 Correct 289 ms 23428 KB Output is correct
13 Correct 290 ms 23796 KB Output is correct
14 Correct 226 ms 24424 KB Output is correct
15 Correct 3 ms 12888 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 4 ms 12892 KB Output is correct
20 Correct 3 ms 12892 KB Output is correct
21 Correct 3 ms 12892 KB Output is correct
22 Correct 3 ms 12892 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 4 ms 12888 KB Output is correct
28 Correct 3 ms 12892 KB Output is correct
29 Correct 4 ms 12892 KB Output is correct
30 Correct 4 ms 13148 KB Output is correct
31 Correct 4 ms 13148 KB Output is correct
32 Correct 3 ms 12892 KB Output is correct
33 Correct 4 ms 13152 KB Output is correct
34 Correct 12 ms 14484 KB Output is correct
35 Correct 324 ms 23652 KB Output is correct
36 Correct 342 ms 23400 KB Output is correct
37 Correct 354 ms 23656 KB Output is correct
38 Correct 339 ms 23356 KB Output is correct
39 Correct 325 ms 23328 KB Output is correct
40 Correct 294 ms 23264 KB Output is correct
41 Correct 321 ms 23796 KB Output is correct
42 Correct 337 ms 23720 KB Output is correct
43 Correct 177 ms 23400 KB Output is correct
44 Correct 345 ms 24276 KB Output is correct
45 Correct 294 ms 29152 KB Output is correct
46 Correct 353 ms 24420 KB Output is correct
47 Correct 324 ms 23400 KB Output is correct
48 Correct 304 ms 24712 KB Output is correct
49 Correct 77 ms 32304 KB Output is correct
50 Correct 76 ms 25940 KB Output is correct
51 Correct 220 ms 26832 KB Output is correct
52 Correct 370 ms 31124 KB Output is correct
53 Correct 331 ms 33216 KB Output is correct
54 Correct 419 ms 35528 KB Output is correct
55 Correct 211 ms 23404 KB Output is correct
56 Correct 414 ms 32536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 13144 KB Output is correct
6 Correct 3 ms 12904 KB Output is correct
7 Correct 3 ms 13052 KB Output is correct
8 Correct 3 ms 12888 KB Output is correct
9 Correct 116 ms 21448 KB Output is correct
10 Correct 236 ms 23364 KB Output is correct
11 Correct 289 ms 23428 KB Output is correct
12 Correct 290 ms 23796 KB Output is correct
13 Correct 226 ms 24424 KB Output is correct
14 Execution timed out 2082 ms 22888 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 13144 KB Output is correct
7 Correct 3 ms 12904 KB Output is correct
8 Correct 3 ms 13052 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Correct 116 ms 21448 KB Output is correct
11 Correct 236 ms 23364 KB Output is correct
12 Correct 289 ms 23428 KB Output is correct
13 Correct 290 ms 23796 KB Output is correct
14 Correct 226 ms 24424 KB Output is correct
15 Execution timed out 2082 ms 22888 KB Time limit exceeded
16 Halted 0 ms 0 KB -