# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
948529 | phone64bit | Commuter Pass (JOI18_commuter_pass) | C++14 | 119 ms | 25156 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;
};
struct edge {
int u, v;
};
vector<edge> k_path, tmp_path;
vector<path> edges[mxN];
bitset<mxN> vs;
ll dp[mxN], k_dp[mxN], ans = 1e18;
int n,m,s,t,u,v;
priority_queue<Q> pq;
void dfs(int u) {
vs[u]=1;
if(u==t&&k_path.size()<tmp_path.size()) {
k_path = tmp_path;
return;
}
for(auto v: edges[u]) if(!vs[v.dest]) vs[v.dest]=1, tmp_path.push_back({u, v.dest}), dfs(v.dest), tmp_path.pop_back();
}
int main() {
for(int i=0; i<mxN; i++) dp[i]=1e18;
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});
}
dfs(s);
for(auto x: k_path) edges[x.u].push_back({x.v, 0}), edges[x.v].push_back({x.u, 0});
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... |