# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60574 | gusfring | Commuter Pass (JOI18_commuter_pass) | C++14 | 806 ms | 19596 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;
const int MAXN = 1e5 + 5;
typedef long long ll;
struct node{
int u;
ll w;
bool operator<(const node &rhs) const{
return w > rhs.w;
}
};
vector<node> adj[MAXN];
int N, M, S, U, T, V;
ll dists[MAXN], distt[MAXN], distu[MAXN], distv[MAXN];
void dijkstra(int cur, ll *dist){
for(int i=1; i<=N; ++i) dist[i] = -1;
dist[cur] = 0;
priority_queue<node> Q;
Q.push((node){cur, 0});
while(!Q.empty()){
node it = Q.top(); Q.pop();
int u = it.u;
ll w = it.w;
for(node it2 : adj[u]){
int v = it2.u;
ll ww = it2.w;
if(dist[v] == -1 || dist[u] + ww < dist[v]){
dist[v] = dist[u] + ww;
Q.push((node){v, dist[v]});
}
}
}
}
int main(){
scanf("%d %d %d %d %d %d", &N, &M, &S, &T, &U, &V);
while(M--){
int u, v, c;
scanf("%d %d %d", &u, &v, &c);
adj[u].push_back((node){v, c});
adj[v].push_back((node){u, c});
}
dijkstra(S, dists);
dijkstra(T, distt);
dijkstra(U, distu);
dijkstra(V, distv);
ll mnu = 1000000000000000000LL, mnv = 1000000000000000000LL, ds = dists[T];
for(int i=1; i<=N; ++i)
if(dists[i] + distt[i] == ds) mnu = min(mnu, distu[i]), mnv = min(mnv, distv[i]);
printf("%lld\n", min(mnu + mnv, distu[V]));
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... |