比赛 4043级NOIP2022欢乐赛6th 评测结果 AAAAAAAAAA
题目名称 旅行者 最终得分 100
用户昵称 HeSn 运行时间 7.654 s
代码语言 C++ 内存使用 40.55 MiB
提交时间 2022-11-18 21:36:15
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 500010;
int n, m, k, a[MAXN], dis[MAXN], pos[MAXN], ans;
bool vis[MAXN];
vector<int> cd[MAXN], w[MAXN];
struct node {
	int num, dis;
	bool operator < (const node& x) const {
		return  x.dis < dis;
	}
}st;
priority_queue<node> q;
int dijkstra(int x) {
	memset(vis, 0, sizeof(vis));
	memset(dis, 0x3f, sizeof(dis));
	dis[x] = 0;
	st.num = x;
	st.dis = dis[x];
	q.push(st);
	while(!q.empty()) {
		int u = q.top().num;
		q.pop();
//			cout << u << ' ';
		if(pos[u] && u != x) {
			return dis[u];
		}
		if(vis[u]) {
			continue;
		}
		vis[u] = 1;
		for(int i = 0; i < cd[u].size(); i ++) {
			int v = cd[u][i];
			if(!vis[v] && dis[v] > dis[u] + w[u][i]) {
				dis[v] = dis[u] + w[u][i];
				st.num = v;
				st.dis = dis[v];
				q.push(st);
			}
		}
	}
	return 1e15;
}
signed main() {
	freopen("WAW.in", "r", stdin);
	freopen("WAW.out", "w", stdout);
	int t;
	cin >> t;
	while(t --) {
	memset(pos, 0, sizeof(pos));
	ans = 1e15;
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i ++) {
		cd[i].clear();
		w[i].clear();
	}
	for(int i = 1; i <= m; i ++) {
		int x, y, z;
		cin >> x >> y >> z;
		cd[x].push_back(y);
		w[x].push_back(z);
	}
	for(int i = 1; i <= k; i ++) {
		int x;
		cin >> x;
		pos[x] = 1;
	}
	for(int i = 1; i <= n; i ++) {
		if(pos[i]) {
//		cout << i << ' ';
			ans = min(ans, dijkstra(i));
		}
	}
	cout << ans << endl;
	}
	return 0;
}