Submission #8130

#TimeUsernameProblemLanguageResultExecution timeMemory
8130baneling100Sightseeing (NOI14_sightseeing)C++98
15 / 25
3500 ms163200 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...