답안 #1065383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065383 2024-08-19T06:50:06 Z Gromp15 봉쇄 시간 (IOI23_closing) C++17
0 / 100
82 ms 24572 KB
#include <bits/stdc++.h>
#include "closing.h"
#define ar array
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
const ll INF = 1e18;
 
int max_score(int n, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W) {
	vector<vector<ar<int, 2>>> adj(n+1);
	for (int i = 0; i < n-1; i++) {
		adj[U[i]].push_back({V[i], W[i]});
		adj[V[i]].push_back({U[i], W[i]});
	}
	vector<vector<ll>> d(2, vector<ll>(n, INF));
	vector<int> p(n, -1);
	auto dfs = [&](auto&& s, int v, vector<ll>& dist) -> void {
		for (auto [u, w] : adj[v]) if (u != p[v]) {
			p[u] = v, dist[u] = dist[v] + w;
			s(s, u, dist);
		}
	};
	d[0][X] = 0, d[1][Y] = 0;
	dfs(dfs, X, d[0]);
	fill(all(p), -1);
	dfs(dfs, Y, d[1]);
	priority_queue<ar<ll, 3>, vector<ar<ll, 3>>, greater<ar<ll, 3>>> q;
	vector<int> ans(n);
	ans[X] = 1, ans[Y] = 2;
	for (auto [u, w] : adj[X]) q.push({d[0][u] - d[0][X], u, 0});
	for (auto [u, w] : adj[Y]) q.push({d[0][u] - d[0][Y], u, 1});
	ll used = 0;
	while (q.size()) {
		auto [cost, v, u] = q.top(); q.pop();
		if (used + cost > K) break;
		used += cost;
		ans[v] |= 1 << u;
		for (auto [u2, w2] : adj[u]) if (!(ans[u2] >> u & 1)) q.push({d[u][u2] - d[u][v], u2, u});
	}
	int ans2 = 0;
	for (int x : ans) ans2 += __builtin_popcount(x);
	return ans2;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 24572 KB 1st lines differ - on the 1st token, expected: '451', found: '8'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -