Submission #981730

# Submission time Handle Problem Language Result Execution time Memory
981730 2024-05-13T13:54:58 Z vjudge1 Swapping Cities (APIO20_swap) C++17
0 / 100
1 ms 4696 KB
#include "swap.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int n, m, i, j, sz[100001], p[100001], d[100001], mx[100001], szm[100001];
vector<pair<int, int>> g[100001];
vector<pair<int, pair<int, int>>> gg;

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

void merge(int xx, int yy) {
	d[xx]++, d[yy]++;
	int x = get(xx), y = get(yy);
	mx[x] = max({mx[x], d[x], d[xx]});
	mx[y] = max({mx[y], d[y], d[yy]});
	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];
}

void init(int N, int M,
          std::vector<int> U, std::vector<int> V, std::vector<int> W) {
	n = N, m = M;
	for (int 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(int md, int x, int y) {
	for (int i = 0; i <= n; i++) sz[i] = 1, p[i] = i, d[i] = mx[i] = szm[i] = 0;
	for (int i = 0; i <= md; i++) merge(gg[i].second.first, gg[i].second.second);
	if (get(x) != get(y)) return 0;
	if (mx[get(x)] < 1) return 0;
	if (mx[get(x)] <= 2 && szm[get(x)] < sz[get(x)]) return 0;
	return 1;
}

int getMinimumFuelCapacity(int X, int Y) {
	int l = 0, r = m - 1, md;
	while (l <= r) {
		md = (l + r) / 2;
		if (check(md, X, Y)) r = md - 1;
		else l = md + 1;
	}
	if (!check(l, X, Y)) return -1;
  return gg[l].first;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -