QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#112454#6523. Escape PlanChtholly_NephrenAC ✓941ms85244kbC++141.4kb2023-06-11 20:02:412023-06-11 20:02:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-11 20:02:44]
  • 评测
  • 测评结果:AC
  • 用时:941ms
  • 内存:85244kb
  • [2023-06-11 20:02:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,n,m,k,d[100005],E[100005],dis[100005],tot,head[100005];
struct edge{
	int to,next,w;
}e[2000005];
void add(int x,int y,int w){
	tot++;
	e[tot].next=head[x];
	e[tot].to=y;
	e[tot].w=w;
	head[x]=tot;
}
struct node{
	int id,dist;
	bool operator < (const node &b) const{
		return dist>b.dist;
	}
};
void dijkstra(){
	priority_queue<node> pq;
	for(int i=1; i<=k; i++)
		for(int j=head[E[i]]; j; j=e[j].next){
			int nxt=e[j].to;
			pq.push(node{nxt,dis[E[i]]+e[j].w});
		}
	while(pq.empty()==false){
		node cur=pq.top();
//		cout<<"addd "<<cur.id<<' '<<dis[cur.id]<<'\n';
		pq.pop();
		if(dis[cur.id]<=1e9||cur.dist>1e9)
			continue;
		if(d[cur.id]>0){
			d[cur.id]--;
			continue;
		}
		dis[cur.id]=cur.dist;
		for(int i=head[cur.id]; i; i=e[i].next){
			int nxt=e[i].to;
			pq.push(node{nxt,dis[cur.id]+e[i].w});
		}
	}
	return;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n>>m>>k;
		tot=0;
		memset(head,0,sizeof head);
		memset(dis,0x3f,sizeof dis);
		for(int i=1; i<=k; i++){
			cin>>E[i];
			dis[E[i]]=0;
		}
		for(int i=1; i<=n; i++)
			cin>>d[i];
		for(int i=1; i<=m; i++){
			int x,y,w;
			cin>>x>>y>>w;
			add(x,y,w);
			add(y,x,w);
		}
		dijkstra();
		if(dis[1]>=1e9)
			cout<<"-1\n";
		else
			cout<<dis[1]<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 941ms
memory: 85244kb

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