This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<int> adjlist[100001];//node
priority_queue<int> weights[100001];
int n,m;
cin>>n>>m;
for (int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
adjlist[b].push_back(a);
weights[a].push(c);
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq;
int dist[100001];
memset(dist,-1,sizeof(dist));
pq.push(make_pair(0,n));
dist[n]=0;
while (!pq.empty()){
pair<int,int> c=pq.top();
pq.pop();
if (c.first!=dist[c.second]) continue;
for (auto curnode:adjlist[c.second]){
int w=weights[curnode].top();
weights[curnode].pop();
if (dist[curnode]==-1 || dist[curnode]>c.first+w){
dist[curnode]=c.first+w;
pq.push(make_pair(dist[curnode],curnode));
}
}
}
cout<<dist[1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |