QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#60585#4479. Slipperqinjianbin#ML 0ms0kbC++171.5kb2022-11-05 16:38:342022-11-05 16:38:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-05 16:38:37]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2022-11-05 16:38:34]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++) 
#define _for(i, a, b) for(int i = (a); i <= (b); i++) 
using namespace std;

typedef long long ll;
const int N = 3e6 + 10;
ll d[N];
struct node
{
	int v; ll w;
	bool operator < (const node& rhs) const
	{
		return w > rhs.w;
	}
};
vector<pair<int, int>> g[N];
vector<int> ve[N];
int n, k, p, s, t, cnt;

void dfs(int u, int fa, int dep)
{
	ve[dep].push_back(u);
	for(auto [v, w]: g[u])
	{
		if(v == fa) continue;
		dfs(v, u, dep + 1);
	}
}

void solve()
{
	_for(i, 1, 3 * n) d[i] = 1e18;
	d[s] = 0;
	priority_queue<node> q;
	q.push({s, d[s]});

	while(!q.empty())
	{
		node x = q.top(); q.pop();
		int u = x.v;
		if(d[u] != x.w) continue;

		for(auto [v, w]: g[u])
			if(d[v] > d[u] + w)
			{
				d[v] = d[u] + w;
				q.push({v, d[v]});
			}
	}
}

int main()
{
	int T; scanf("%d", &T);
	while(T--)
	{
		scanf("%d", &n);
		_for(i, 1, 3 * n) g[i].clear(), ve[i].clear();
		_for(i, 1, n - 1)
		{
			int u, v, w;
			scanf("%d%d%d", &u, &v, &w);
			g[u].push_back({v, w});
			g[v].push_back({u, w});
		}
		scanf("%d%d%d%d", &k, &p, &s, &t);

		dfs(1, 0, 1);

		cnt = n;
		_for(i, 1, n)
		{
			int j = i + k;
			if(!ve[j].size()) break;
			cnt++;
			for(int x: ve[i])  g[x].push_back({cnt, 0});
			for(int y: ve[j])  g[cnt].push_back({y, p});
			cnt++;
			for(int x: ve[i])  g[cnt].push_back({x, 0});
			for(int y: ve[j])  g[y].push_back({cnt, p});
		}

		solve();
		printf("%lld\n", d[t]);
	}

	return 0; 
} 

详细

Test #1:

score: 0
Memory Limit Exceeded

input:

5
121753
103252 40559 325002
32674 51809 946614
18343 12099 625962
27677 48601 114048
11146 12478 906161
121147 77390 208299
39512 95642 154696
90603 43508 378490
4829 7818 191754
73699 31412 536840
106916 89894 374802
113739 90049 411062
113123 73246 740213
38047 120942 903325
51907 41500 822541
90...

output:


result: