QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783924#6660. 택시 여행jiamengtongCompile Error//C++142.3kb2024-11-26 12:17:012024-11-26 12:17:40

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 12:17:40]
  • 评测
  • [2024-11-26 12:17:01]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define i32 int
#define M 100005
using namespace std;
vector<pair<int, int> > v[M], G[M];
int sz[M], hson[M], fa[M], dep[M], dis[M], top[M], ndis[M], vis[M];
void dfs(int x, int ft)
{
	sz[x] = 1;
	fa[x] = ft;
	dep[x] = dep[ft] + 1;
	for(auto t : v[x])
	{
		int to = t.first, dist = t.second;
		if(to == ft) continue;
		dis[to] = dis[x] + dist;
		dfs(to, x);
		sz[x] += sz[to];
		if(sz[to] > sz[hson[x]]) hson[x] = to;
	}
}
void dfs1(int x, int tp)
{
	top[x] = tp;
	if(hson[x]) dfs1(hson[x], tp);
	for(auto t : v[x]) if(t.first != fa[x] && t.first != tp) dfs1(t.first, t.first);
}
int LCA(int x, int y)
{
	while(top[x] != top[y])
	{
		if(dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	if(dep[x] > dep[y]) swap(x, y);
	return x;
}
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
std::vector<long long> travel(std::vector<long long> A, std::vector<i32> B, std::vector<i32> U, std::vector<i32> V, std::vector<i32> W)
{
	int n = A.size();
	for(int i = 0; i < n - 1; i++) v[U[i]].push_back({V[i], W[i]}), v[V[i]].push_back({U[i], W[i]});
	dfs(0, -1);
	dfs1(0, -1);
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j)
	{
		int dst = dis[i] + dis[j] - dis[LCA(i, j)] * 2;
//		cout << i << " " << j << " " << dst << " " << A[i] + dst * B[i] << endl;
		G[i].push_back({j, A[i] + dst * B[i]});
	}
	for(int i = 1; i < n; i++) ndis[i] = 3e18;
	ndis[0] = 0;
	pq.push({0, 0});
	while(pq.size())
	{
		int u = pq.top().first;
		pq.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		for(auto t : G[u])
		{
			if(ndis[t.first] > ndis[u] + t.second)
			{
				ndis[t.first] = ndis[u] + t.second;
				pq.push({t.first, t.second});
			}
		}
	}
	vector<int> res;
	for(int i = 1; i < n; i++) res.push_back(ndis[i]);
	return res;
}
//signed main()
//{
//	int n;
//	scanf("%lld", &n);
//	vector<int> A, B, U, V, W;
//	for(int i = 1, x; i <= n; i++) scanf("%lld", &x), A.push_back(x);
//	for(int i = 1, x; i <= n; i++) scanf("%lld", &x), B.push_back(x);
//	for(int i = 1, x, y, z; i < n; i++) scanf("%lld%lld%lld", &x, &y, &z), U.push_back(x), V.push_back(y), W.push_back(z);
//	vector<int> res = travel(A, B, U, V, W);
//	for(int i = 0; i < n - 1; i++) printf("%lld ", res[i]);
//	puts("");
//	return 0;
//}

Details

/usr/bin/ld: /tmp/ccRZEhVY.o: in function `main':
implementer.cpp:(.text.startup+0x35e): undefined reference to `travel(std::vector<long long, std::allocator<long long> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status