제출 #1327287

#제출 시각아이디문제언어결과실행 시간메모리
1327287tkm_algorithms공장들 (JOI14_factories)C++20
0 / 100
8093 ms49624 KiB
#include "factories.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
//#define int ll
using P = pair<int, int>;
using PL = pair<ll, int>;
#define all(x) x.begin(), x.end()
#define rep(i, l, n) for (int i = l; i < (n); ++i)
#define sz(x) (int)x.size()
const char nl = '\n';
const int NMAX = 5e5+10;
const ll inf = NMAX*(ll)1e9;
vector<P> g[NMAX];
ll d[NMAX];
int specific[NMAX], NN;

void Init(int N, int A[], int B[], int D[]) {
	NN = N;
	rep(i, 0, N-1)
		g[A[i]].push_back({B[i], D[i]}),
		g[B[i]].push_back({A[i], D[i]});
}

long long Query(int S, int X[], int T, int Y[]) {
	rep(i, 0, NN)d[i] = inf, specific[i] = 0;
	rep(i, 0, T)specific[Y[i]] = 1;
	priority_queue<PL, vector<PL>, greater<PL>> pq;
	rep(i, 0, S) {
		pq.push({0, X[i]});
		d[X[i]] = 0;
	}
	
	while (!pq.empty()) {
		auto [dist, nd] = pq.top(); pq.pop();
		if (d[nd] != dist)continue;
		if (specific[nd])return dist;
		for (auto [son, w]: g[nd])
			if (dist+w < d[son])
				d[son] = dist+w,
				pq.push(P(d[son], son));
	}
	
	assert(1==0);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...