Submission #269791

# Submission time Handle Problem Language Result Execution time Memory
269791 2020-08-17T10:20:38 Z sean9892 None (KOI16_gas) C++14
100 / 100
122 ms 50336 KB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using dat=pair<ll,pii>;
#define fi first
#define se second

vector<pii> g[2510];
int cst[2510];
ll dst[2510][2510];

int main(void){
	ios::sync_with_stdio(0);cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>cst[i];
	}
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		g[a].emplace_back(b,c);
		g[b].emplace_back(a,c);
	}
	
	memset(dst,0x3f,sizeof(dst));
	dst[1][cst[1]]=0;
	priority_queue<dat> q;
	
	ll res=0x3f3f3f3f3f3f3f3f;
	
	#define pushDat(d,x,c) q.push(dat(-(d),pii(x,c)))
	#define popDat(d,x,c) do{d=-q.top().fi;x=q.top().se.fi;c=q.top().se.se;q.pop();}while(0)
	
	pushDat(0,1,cst[1]);
	while(!q.empty()){
		ll d;
		int x,c;
		popDat(d,x,c);
		if(dst[x][c]<d)continue;
		if(x==n){
			res=min(res,d);
		}
		for(auto& e:g[x]){
			int i,w;
			tie(i,w)=e;
			if(dst[i][min(c,cst[i])]>d+c*w){
				dst[i][min(c,cst[i])]=d+c*w;
				pushDat(d+c*w,i,min(c,cst[i]));
			}
		}
	}
	
	#undef pushDat
	#undef popDat
	
	cout<<res;
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 49656 KB Output is correct
2 Correct 29 ms 49664 KB Output is correct
3 Correct 29 ms 49656 KB Output is correct
4 Correct 29 ms 49664 KB Output is correct
5 Correct 29 ms 49664 KB Output is correct
6 Correct 29 ms 49656 KB Output is correct
7 Correct 29 ms 49664 KB Output is correct
8 Correct 30 ms 49664 KB Output is correct
9 Correct 31 ms 49664 KB Output is correct
10 Correct 32 ms 49664 KB Output is correct
11 Correct 30 ms 49656 KB Output is correct
12 Correct 29 ms 49656 KB Output is correct
13 Correct 29 ms 49664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 49784 KB Output is correct
2 Correct 31 ms 49784 KB Output is correct
3 Correct 35 ms 49784 KB Output is correct
4 Correct 36 ms 49792 KB Output is correct
5 Correct 32 ms 49792 KB Output is correct
6 Correct 31 ms 49784 KB Output is correct
7 Correct 31 ms 49888 KB Output is correct
8 Correct 33 ms 49912 KB Output is correct
9 Correct 30 ms 49788 KB Output is correct
10 Correct 37 ms 49792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 49792 KB Output is correct
2 Correct 31 ms 49912 KB Output is correct
3 Correct 31 ms 49920 KB Output is correct
4 Correct 32 ms 49912 KB Output is correct
5 Correct 33 ms 49920 KB Output is correct
6 Correct 32 ms 49912 KB Output is correct
7 Correct 32 ms 49912 KB Output is correct
8 Correct 32 ms 49912 KB Output is correct
9 Correct 31 ms 49912 KB Output is correct
10 Correct 37 ms 49912 KB Output is correct
11 Correct 31 ms 49912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 49656 KB Output is correct
2 Correct 29 ms 49664 KB Output is correct
3 Correct 29 ms 49656 KB Output is correct
4 Correct 29 ms 49664 KB Output is correct
5 Correct 29 ms 49664 KB Output is correct
6 Correct 29 ms 49656 KB Output is correct
7 Correct 29 ms 49664 KB Output is correct
8 Correct 30 ms 49664 KB Output is correct
9 Correct 31 ms 49664 KB Output is correct
10 Correct 32 ms 49664 KB Output is correct
11 Correct 30 ms 49656 KB Output is correct
12 Correct 29 ms 49656 KB Output is correct
13 Correct 29 ms 49664 KB Output is correct
14 Correct 36 ms 49688 KB Output is correct
15 Correct 29 ms 49784 KB Output is correct
16 Correct 29 ms 49716 KB Output is correct
17 Correct 52 ms 50168 KB Output is correct
18 Correct 52 ms 50176 KB Output is correct
19 Correct 38 ms 49784 KB Output is correct
20 Correct 32 ms 49784 KB Output is correct
21 Correct 33 ms 49784 KB Output is correct
22 Correct 32 ms 49792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 49656 KB Output is correct
2 Correct 29 ms 49664 KB Output is correct
3 Correct 29 ms 49656 KB Output is correct
4 Correct 29 ms 49664 KB Output is correct
5 Correct 29 ms 49664 KB Output is correct
6 Correct 29 ms 49656 KB Output is correct
7 Correct 29 ms 49664 KB Output is correct
8 Correct 30 ms 49664 KB Output is correct
9 Correct 31 ms 49664 KB Output is correct
10 Correct 32 ms 49664 KB Output is correct
11 Correct 30 ms 49656 KB Output is correct
12 Correct 29 ms 49656 KB Output is correct
13 Correct 29 ms 49664 KB Output is correct
14 Correct 31 ms 49784 KB Output is correct
15 Correct 31 ms 49784 KB Output is correct
16 Correct 35 ms 49784 KB Output is correct
17 Correct 36 ms 49792 KB Output is correct
18 Correct 32 ms 49792 KB Output is correct
19 Correct 31 ms 49784 KB Output is correct
20 Correct 31 ms 49888 KB Output is correct
21 Correct 33 ms 49912 KB Output is correct
22 Correct 30 ms 49788 KB Output is correct
23 Correct 37 ms 49792 KB Output is correct
24 Correct 37 ms 49792 KB Output is correct
25 Correct 31 ms 49912 KB Output is correct
26 Correct 31 ms 49920 KB Output is correct
27 Correct 32 ms 49912 KB Output is correct
28 Correct 33 ms 49920 KB Output is correct
29 Correct 32 ms 49912 KB Output is correct
30 Correct 32 ms 49912 KB Output is correct
31 Correct 32 ms 49912 KB Output is correct
32 Correct 31 ms 49912 KB Output is correct
33 Correct 37 ms 49912 KB Output is correct
34 Correct 31 ms 49912 KB Output is correct
35 Correct 36 ms 49688 KB Output is correct
36 Correct 29 ms 49784 KB Output is correct
37 Correct 29 ms 49716 KB Output is correct
38 Correct 52 ms 50168 KB Output is correct
39 Correct 52 ms 50176 KB Output is correct
40 Correct 38 ms 49784 KB Output is correct
41 Correct 32 ms 49784 KB Output is correct
42 Correct 33 ms 49784 KB Output is correct
43 Correct 32 ms 49792 KB Output is correct
44 Correct 36 ms 49784 KB Output is correct
45 Correct 32 ms 49784 KB Output is correct
46 Correct 33 ms 49884 KB Output is correct
47 Correct 49 ms 50336 KB Output is correct
48 Correct 51 ms 50296 KB Output is correct
49 Correct 104 ms 50168 KB Output is correct
50 Correct 53 ms 50040 KB Output is correct
51 Correct 122 ms 50296 KB Output is correct
52 Correct 94 ms 50168 KB Output is correct