| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 833168 | vjudge1 | Commuter Pass (JOI18_commuter_pass) | C++98 | 0 ms | 0 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
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
const ll N = 1e5+10;
ll n,m,u,v,s,t;
ll temp,a,b,c;
map<ll,bool> iszero[100100];
vector<pii> adj[N];
vector<ll> pass;
priority_queue<pii,vector<pii>,greater<pii>> pq;
bool vis[N];
ll dist[N],pre[N];
void f(ll x) {
if(pre[x] != 0) {
f(pre[x]);
pass.pb(x);
}
}
int main() {
cin >> n >> m;
cin >> s >> t;
cin >> u >> v;
for(int i=1; i<=m; i++) {
cin >> a >> b >> c;
adj[a].pb({b,c});
adj[b].pb({a,c});
}
for(int i=1; i<=n; i++) dist[i] = 1e18;
pq.push({0,s});
dist[s] = 0;
while(!pq.empty()) {
pii x = pq.top();
pq.pop();
for(auto i : adj[x.se]) {
if(dist[i.fi] > dist[x.se] + i.se) {
dist[i.fi] = dist[x.se] + i.se;
pq.push({dist[i.fi],i.fi});
pre[i.fi] = x.se;
}
}
}
// cout << "dist " << endl;
// for(int i=1; i<=n; i++) {
// cout << dist[i] << endl;
// }
// cout << "prev " << endl;
// for(int i=1; i<=n; i++) {
// cout << pre[i] << endl;
// }
pass.pb(s);
f(t);
// cout << "pass ";
// for(auto i : pass) {
// cout << i << " ";
// }
// cout << endl;
for(int i=1; i<pass.size(); i++) {
iszero[pass[i-1]][pass[i]] = true;
}
for(int i=1; i<=n; i++) dist[i] = 1e18;
pq.push({0,u});
dist[u] = 0;
while(!pq.empty()) {
pii x = pq.top();
pq.pop();
for(auto i : adj[x.se]) {
if(iszero[x.se][i.fi]) temp = 0;
else temp = i.se;
if(dist[i.fi] > dist[x.se] + temp) {
dist[i.fi] = dist[x.se] + temp;
pq.push({dist[i.fi],i.fi});
}
}
}
cout << dist[v] << endl;
}
