Submission #1008335

# Submission time Handle Problem Language Result Execution time Memory
1008335 2024-06-26T09:33:43 Z overwatch9 Swapping Cities (APIO20_swap) C++17
0 / 100
0 ms 348 KB
#include "swap.h"

#include <bits/stdc++.h>
using namespace std;

vector <vector <pair <int, int>>> adj;
int n, m;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
	// cout.tie(0);
    adj.resize(N+1);
	n = N;
	m = M;
    for (int i = 0; i < M; i++) {
        adj[U[i]].push_back({V[i], W[i]});
		adj[V[i]].push_back({U[i], W[i]});
	}
}
const int maxn = 1e5 + 1;
int dis[maxn];
priority_queue <pair <int, int>> pq;
bool vis[maxn], processed[maxn];
bool skip = true;
int dfs(int s, int p, int st) {
	if (s == st && !skip) {
		return 0;
	}
	skip = false;
	if (vis[s])
		return 1e9;
	vis[s] = true;
	int ans = 1e9;
	for (auto i : adj[s]) {
		if (i.first == p)
			continue;
		ans = min(ans, max(i.second, dfs(i.first, s, st)));
	}
	vis[s] = false;
	return ans;
}
int getMinimumFuelCapacity(int x, int y) {
	fill(processed, processed + n + 1, false);
	pq.push({0, x});
	fill(dis, dis + n + 1, 1e9 + 1);
	dis[x] = 0;
	while (!pq.empty()) {
		int s = pq.top().second;
		pq.pop();
		if (processed[s])
			continue;
		processed[s] = true;
		for (auto i : adj[s]) {
			int d = max(dis[s], i.second);
			if (d < dis[i.first]) {
				dis[i.first] = d;
				pq.push({-d, i.first});
			}
		}
	}
	if (dis[y] == 1e9 + 1)
		return -1;
	skip = true;
	fill(vis, vis + n + 1, false);
	int ans = dfs(x, x, x);
	return max(ans, dis[y]);
}
// int main() {
// 	int N, M;
// 	cin >> N >> M;
// 	vector <int> u(M), v(M), w(M);
// 	for (int i = 0; i < M; i++)
// 		cin >> u[i] >> v[i] >> w[i];
// 	init(N, M, u, v, w);
// 	int q;
// 	cin >> q;
// 	while (q--) {
// 		int x, y;
// 		cin >> x >> y;
// 		cout << getMinimumFuelCapacity(x, y) << '\n';
// 	}
// }
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -