社区讨论

代码 50pts WA on #2,球条,玄关

P9650 [SNCPC2019] Escape Plan参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mhizu8l9
此快照首次捕获于
2025/11/03 18:24
4 个月前
此快照最后确认于
2025/11/03 18:24
4 个月前
查看原帖
CPP
// Problem: D - Escape Plan
// Contest: Virtual Judge - 20251027作业
// URL: https://vjudge.net/contest/761251#problem/D
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;

#define fir first
#define sec second

#define int long long
#ifdef int
const int INF=0x3f3f3f3f3f3f3f3f;
#else
const int INF=0x3f3f3f3f;
#endif

#define P 998244353
#ifndef P
#define P 1000000007
#endif

#define fstopen 1
#ifdef fstopen
#define fst ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#else
#define fst ;
#endif

const int N=1e6+5,M=1e3+5;

//��״���� 
//struct BIT{
//	int bit[N];
//	int lowbit(int x){return x&-x;}
//	void update(int x,int y){for(;x<=n;x+=lowbit(x))bit[x]+=y;}
//	int query(int x){int s=0;for(;x;x-=lowbit(x))s+=bit[x];return s;}
//};

//���鼯
//int fa[N];
//int fifa(int x){
//	if(fa[x]==x)return x;
//	return fa[x]=fifa(fa[x]);
//}

int n,m,k;
int e[N];
int d[N];
int s[N];
vector<pair<int,int> > g[N];

//������
signed code(){
	cin >> n >> m >> k;
	for(int i=1;i<=n;i++){
		s[i]=INF;
	}
	for(int i=1;i<=n;i++){
		g[i].clear();
	}
	for(int i=1;i<=k;i++){
		cin >> e[i];
	}
	for(int i=1;i<=n;i++){
		cin >> d[i];
	}
	for(int i=1;i<=m;i++){
		int u,v,w;
		cin >> u >> v >> w;
		g[u].push_back({v,w});
		g[v].push_back({u,w});
	}
	priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > q;
	for(int i=1;i<=k;i++){
		q.push({0,e[i]});
		s[e[i]]=0;
	}
	while(!q.empty()){
		int x=q.top().sec;
		int y=q.top().fir;
		// cout << x << ' ' << y << ' ' << d[1] << endl;
		q.pop();
		if(s[x]!=y)continue;
		for(auto e:g[x]){
			if(e.sec+y>=s[e.fir])continue;
			if(d[e.fir]!=0){
				d[e.fir]--;
				continue;
			}
			s[e.fir]=e.sec+y;
			q.push({s[e.fir],e.fir});
		}
	}
	if(s[1]==INF)cout << -1 << endl;
	else cout << s[1] << endl;
	return 0;
}

signed main(){
	fst;
	int t=1;
	cin >> t;
	while(t--){
		code();
	}
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...