#include <bits/stdc++.h>
#define int long long
//#define double long double
#define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<int, int>
#define ALL(i) i.begin(),i.end()
#define gcd(i,j) __gcd(i,j)
#define fi first
#define se second
#define eps 0.00000001
#define ist insert
#define DNE nullptr
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
int max(int x,int y){return x>=y?x:y;}
int min(int x,int y){return x>=y?y:x;}
using namespace std;
typedef int ll;
const int N=500005;
const int M=1000005;
const int MOD=1000000007;//998244353;
const int INF=1000000000000000000;//2147483647;
int n,m,Q;
vector<pi> e[N];
int d[N];
priority_queue<pi,vector<pi>,greater<pi>> pq;
void dij(){
memset(d,-1,sizeof(d));
pq.push({INF,1});
while (pq.size()){
int v=pq.top().se,c=pq.top().fi;pq.pop();
if (c<d[v]) continue;
for (auto &i:e[v]){
if (d[i.fi]<min(i.se,c)){
d[i.fi]=min(i.se,c);
pq.push({min(c,i.se),i.fi});
}
}
}
}
/*
4 4 2
1 2 10
1 3 30
2 4 20
3 4 5
3
4*/
inline void sol(){
cin >>n>>m>>Q;
for (int i=0,a,b,c;i<m;i++){
cin >>a>>b>>c;
e[a].pb({b,c});
e[b].pb({a,c});
}
dij();
for (int i=0,t;i<Q;i++){
cin >>t;
cout <<d[t]<<'\n';
}
}
signed main(){
Nanase_Kurumi_aka_menhera_chan_is_mine
int _=1;
//cin >>_;
while (_--) sol();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15948 KB |
Output is correct |
2 |
Correct |
10 ms |
15904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
16220 KB |
Output is correct |
2 |
Correct |
15 ms |
15980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3587 ms |
19864 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3556 ms |
243596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |