#include <bits/stdc++.h>
#define PB push_back
using namespace std;
struct El {
int to, w;
El(int cel, int suly) {
w=suly;
to=cel;
}
El() { }
const bool operator< (El masik) const {
return w<masik.w;
}
};
const int maxn=500005;
vector<El> graf[maxn];
int d[maxn];
bool volte[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin>>n>>m>>q;
for(int i=0;i<m;i++) {
int u, v, w;
cin>>u>>v>>w;
u--; v--;
graf[u].PB(El(v,w));
graf[v].PB(El(u,w));
}
El kezdo(0,INT_MAX);
priority_queue<El> kovi;
kovi.push(kezdo);
int kesz=0;
while(!kovi.empty() && kesz<n) {
El akt=kovi.top();
kovi.pop();
if(!volte[akt.to]) {
volte[akt.to]=true;
kesz++;
d[akt.to]=akt.w;
for(El s:graf[akt.to]) {
s.w=min(s.w,akt.w);
if(!volte[s.to] && (d[s.to]==0 || d[s.to]>s.w)) {
kovi.push(s);
}
}
}
}
vector<int> sol;
for(int i=0;i<q;i++) {
int z;
cin>>z;
z--;
sol.push_back(d[z]);
}
for(int d:sol) {
cout<<d<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12024 KB |
Output is correct |
2 |
Correct |
11 ms |
12132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12336 KB |
Output is correct |
2 |
Correct |
12 ms |
12336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
14564 KB |
Output is correct |
2 |
Correct |
53 ms |
14564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3556 ms |
131144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |