#include <stdio.h>
#include <algorithm>
#define INF 0x7fffffff
using namespace std;
typedef pair <int,int> ppair;
pair <int,ppair> Road[10000001];
pair <int,int> Heap[5000001];
int V, E, Q, D[500001], Check[500001], Size, Start[500001];
void input(void) {
int i, v1, v2, q;
scanf("%d %d %d",&V,&E,&Q);
for(i=1 ; i<=E ; i++) {
scanf("%d %d %d",&v1,&v2,&q);
Road[2*i-1]=make_pair(v1,make_pair(v2,q));
Road[2*i]=make_pair(v2,make_pair(v1,q));
}
sort(Road+1,Road+2*E+1);
for(i=1 ; i<=2*E ; i++)
if(!Start[Road[i].first])
Start[Road[i].first]=i;
}
void process(void) {
int i, Now, Value;
for(i=2 ; i<=V ; i++)
D[i]=-1;
D[1]=INF;
Size=1;
Heap[0]=make_pair(D[1],1);
while(Size) {
Now=Heap[0].second;
pop_heap(Heap,Heap+Size);
Size--;
if(Check[Now])
continue;
Check[Now]=1;
i=Start[Now];
while(i<=2*E && Road[i].first==Now) {
Value=min(D[Now],Road[i].second.second);
if(D[Road[i].second.first]<Value) {
D[Road[i].second.first]=Value;
Heap[Size++]=make_pair(Value,Road[i].second.first);
push_heap(Heap,Heap+Size);
}
i++;
}
}
}
void output(void) {
int i, X;
for(i=1 ; i<=Q ; i++) {
scanf("%d",&X);
printf("%d\n",D[X]);
}
}
int main(void) {
input();
process();
output();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
163200 KB |
Output is correct |
2 |
Correct |
28 ms |
163200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
163200 KB |
Output is correct |
2 |
Correct |
36 ms |
163200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
163200 KB |
Output is correct |
2 |
Correct |
52 ms |
163200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2712 ms |
163200 KB |
Output is correct |
2 |
Execution timed out |
3500 ms |
163200 KB |
Program timed out |