# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
948495 | phone64bit | Commuter Pass (JOI18_commuter_pass) | C++17 | 101 ms | 16068 KiB |
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;
#define ll long long
const int mxN = 1e5+10;
struct Q {
int src; ll w;
bool operator < (const Q&rhs) const {
return w>rhs.w;
}
};
struct path {
int dest; ll w;
};
vector<path> edges[mxN];
ll dp[mxN], ans = 1e18;
priority_queue<Q> pq;
int main() {
for(int i=0; i<mxN; i++) dp[i]=1e18;
int n,m,s,t,u,v; scanf("%d%d%d%d%d%d", &n,&m,&s,&t,&u,&v);
while(m--) {
int u, v; ll w; scanf("%d%d%lld", &u, &v, &w);
edges[u].push_back({v, w});
edges[v].push_back({u, w});
}
dp[u] = 0;
pq.push({u, 0});
while(!pq.empty()) {
auto [src, w] = pq.top();
pq.pop();
if(src==v) {
ans=w;
break;
}
for(auto v: edges[src]) {
if(dp[v.dest]>w+v.w) {
dp[v.dest]=w+v.w;
pq.push({v.dest, dp[v.dest]});
}
}
}
printf("%lld", ans);
return 0;
}
Compilation message (stderr)
# | 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... |