QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#247528#6523. Escape PlangzzzAC ✓664ms78320kbC++201.5kb2023-11-11 14:47:162023-11-11 14:47:16

Judging History

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

  • [2023-11-11 14:47:16]
  • 评测
  • 测评结果:AC
  • 用时:664ms
  • 内存:78320kb
  • [2023-11-11 14:47:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
vector<pair<int,ll>> e[maxn];
ll num[maxn],dis[maxn],n,m,k;;
bool ex[maxn],vis[maxn];
struct node{
	int fr;
	ll w;
	friend bool operator <(node x,node y){ 	
		return x.w>y.w;
	}
};
void dij(){
	priority_queue<node,vector<node>> sq;
	for(int i=1;i<=n;i++){
		if(ex[i]) {
			dis[i]=0;
			num[i]=0;
			sq.push((node){i,dis[i]});
		}
	}
	while(!sq.empty()){
		int now=sq.top().fr;
		ll di=sq.top().w;
		sq.pop();
		if(num[now]) {
			num[now]--;
			continue;
		}
		if(vis[now]) continue;
		vis[now]=true;
		dis[now]=di;
		for(int i=0;i<e[now].size();i++){
			int to=e[now][i].first,w=e[now][i].second;
			if(dis[to]>dis[now]+w){
				sq.push((node){to,dis[now]+w});
			}
		}
	}
	return ;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;cin>>t;
	while(t--) {
		cin>>n>>m>>k;
		for(int i=1;i<=n;i++){
			e[i].clear();
			dis[i]=1e18;
			num[i]=0;
			ex[i]=false;
			vis[i]=false;
		}
		for(int i=1;i<=k;i++) {
			int x;cin>>x;
			ex[x]=true;
		}
		for(int i=1;i<=n;i++){
			cin>>num[i];
		}
		for(int i=1;i<=m;i++){
			int fr,to,w;
			cin>>fr>>to>>w;
			e[fr].push_back(pair<int,ll>(to,w));
			e[to].push_back(pair<int,ll>(fr,w));
		}
		dij();
		if(dis[1]==1e18) cout<<"-1\n";
		else cout<<dis[1]<<"\n";
	}
}
/*
  2
  3 4 1
  3
  1 1 1
  1 2 1
  1 2 2
  2 3 1
  2 3 2
  3 2 2
  2 3
  2 0 0
  1 2 1
  1 3 1

 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7140kb

input:

2
3 4 1
3
1 1 1
1 2 1
1 2 2
2 3 1
2 3 2
3 2 2
2 3
2 0 0
1 2 1
1 3 1

output:

4
-1

result:

ok 2 number(s): "4 -1"

Test #2:

score: 0
Accepted
time: 664ms
memory: 78320kb

input:

100
100 1808 2
94 47
3 3 0 2 4 3 3 4 0 0 2 2 2 3 2 4 0 2 3 4 4 2 0 3 4 3 1 0 2 1 2 2 0 3 4 4 4 1 2 2 3 1 0 0 3 1 4 2 1 3 3 4 3 0 4 1 0 3 2 1 4 4 1 3 2 3 3 3 3 1 0 3 0 4 3 1 0 4 0 4 4 1 2 0 0 4 1 3 3 3 0 2 2 1 1 2 3 4 1 2
72 29 1138
59 78 2398
95 5 1610
32 46 4176
36 99 8143
100 69 413
61 58 1595
9 9...

output:

5109
1021
3293
4646
3796
3394
1884
6772
2329
2067
3296
2809
865
4249
2241
3792
2135
2544
3343
1775
10602
4677
1700
2150
7071
14055
3368
2322
1113
1980
3067
1617
1702
-1
2879
6265
2065
2810
2289
3001
402
3769
18118
6874
7879
3823
-1
510
2636
10564
-1
3166
3615
7526
5549
1261
3302
270
4440
1998
3350
3...

result:

ok 100 numbers