# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255408 | tleontest1 | Commuter Pass (JOI18_commuter_pass) | C++17 | 514 ms | 42720 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.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define int long long
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,u,v,s,visit[li],d[li],vis[li];
int cev;
vector<PII> vec[li];
inline void sp(){
priority_queue<PII> pq;
pq.push({0,t});
while(pq.size()){
int node=pq.top().se;
int co=-pq.top().fi;
pq.pop();
if(vis[node])continue;
vis[node]=1;
d[node]=co;
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i].fi;
int ind=vec[node][i].se;
pq.push({-co-a[ind],go});
}
}
//~ cout<<d[s]<<endl;
memset(vis,0,sizeof(vis));
pq.push({0,s});
while(pq.size()){
int node=pq.top().se;
int co=-pq.top().fi;
pq.pop();
if(vis[node])continue;
vis[node]=1;
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i].fi;
int ind=vec[node][i].se;
//~ cout<<go<<" : : "<<co<<" : : "<<d[go]<<" : : "<<a[ind]<<endl;
if(d[go]+co+a[ind]==d[s])visit[ind]=1;
pq.push({-co-a[ind],go});
}
}
memset(vis,0,sizeof(vis));
priority_queue<PII> pq1;
pq1.push({0,u});
while(pq1.size()){
int node=pq1.top().se;
int co=-pq1.top().fi;
pq1.pop();
if(vis[node])continue;
vis[node]=1;
if(node==v){printf("%lld\n",co);exit(0);}
for(int i=0;i<(int)vec[node].size();i++){
int go=vec[node][i].fi;
int ind=vec[node][i].se;
int coo=co;
if(visit[ind]==0)coo+=a[ind];
//~ cout<<visit[ind]<<" () "<<ind<<endl;
pq1.push({-coo,go});
}
}
}
main(void){
scanf("%lld %lld",&n,&m);
scanf("%lld %lld",&s,&t);
scanf("%lld %lld",&u,&v);
for(int i=1;i<=m;i++){
int x,y;
scanf("%lld %lld %lld",&x,&y,&a[i]);
vec[x].pb({y,i});
vec[y].pb({x,i});
}
sp();
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... |