답안 #700990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700990 2023-02-19T15:48:17 Z angelo_torres 공장들 (JOI14_factories) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "factories.h"
#define ff first
#define ss second

using namespace std;
typedef long long ll;
const ll N = 5e5 + 10;
const ll M = 2e6 + 20;
const ll inf = 1e17;

int n,t[N],p[N];
ll d[N],q[N];
vector<pair<int,ll>> g[N];
deque<ll> s[N];

void dfs(int v,int f){
	t[v] = 1;
	for(auto [u,w] : g[v]){
		if(u == f) continue;
		dfs(u,v);
		t[v] += t[u];
	}
}

int find(int v,int f,int tm){
	for(auto [u,w] : g[v]){
		if(u == f) continue;
		if(t[u]*2 > tm) return find(u,v,tm);
	}
	return v;
}

void gfs(int v,int f){
	s[v].push_front(d[v]);
	for(auto [u,w] : g[v]){
		if(u == f) continue;
		d[u] = d[v] + w;
		gfs(u,v);
	}
}

void build(int v,int f){
	dfs(v,f);
	int c = find(v,f,t[v]);
	d[v] = 0, p[c] = f;
	gfs(v,f);
	for(auto [u,w] : g[c]){
		if(u == f) continue;
		build(u,c);
	}
}

void Init(int N, int A[], int B[], int D[]){
	n = N;
	for(int i = 0; i < n; ++i){
		g[A[i]].push_back({B[i],(ll) D[i]});
		g[B[i]].push_back({A[i],(ll) D[i]});
	}
	build(0,-1);
}

long long Query(int S, int X[], int T, int Y[]){
	for(int i = 0; i < S; ++i){
		int aux = X[i], id = 0;
		while(aux != -1){
			q[aux] = min(q[aux],s[x[i]][id]);
			aux = p[aux], id++;
		}
	}
	ll ans = inf;
	for(int i = 0; i < T; ++i){
		int aux = Y[i], id = 0;
		while(aux != -1){
			ans = min(ans,q[aux]+s[y[i]][id]);
			aux = p[aux], id++;
		}
	}
	for(int i = 0; i < S; ++i){
		int aux = x[i];
		while(aux != -1) q[aux] = inf, aux = p[aux];
	}
	return ans;
}

Compilation message

factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:67:26: error: 'x' was not declared in this scope
   67 |    q[aux] = min(q[aux],s[x[i]][id]);
      |                          ^
factories.cpp:75:27: error: 'y' was not declared in this scope
   75 |    ans = min(ans,q[aux]+s[y[i]][id]);
      |                           ^
factories.cpp:80:13: error: 'x' was not declared in this scope
   80 |   int aux = x[i];
      |             ^