# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
77172 | Vardanyan | Commuter Pass (JOI18_commuter_pass) | C++14 | 271 ms | 263168 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 N = 200*1000+7;
const long long INF = 1000000000000005;
vector<pair<int,long long> > g[N];
long long dist[N];
long long D[N];
long long ans = INF;
int n,m;
int s,t;
int U,V;
vector<vector<int> > all;
bool col[N];
map<pair<int,int>,bool > mp;
vector<int> now;
void dfs(int v,long long ds = 0){
now.push_back(v);
if(v == t){
all.push_back(now);
return;
}
for(int i = 0;i<g[v].size();i++){
pair<int,long long> to = g[v][i];
if(ds+to.second>dist[to.first]) continue;
if(col[to.first]) continue;
col[to.first] = 1;
dfs(to.first,ds+to.second);
col[to.first] = 0;
}
}
void go(int v,long long ds = 0){
D[v] = ds;
if(v == V){
ans = min(ans,ds);
return;
}
for(int i = 0;i<g[v].size();i++){
pair<int,long long> to = g[v][i];
if(mp[{v,to.first}]) to.second = 0;
if(ds+to.second>=D[to.first]) continue;
if(col[to.first]) continue;
col[to.first] = 1;
go(to.first,ds+to.second);
col[to.first] = 0;
}
}
int main(){
scanf("%d%d",&n,&m);
scanf("%d%d",&s,&t);
scanf("%d%d",&U,&V);
for(int i = 0;i<m;i++){
int x,y;
long long z;
scanf("%d%d%lld",&x,&y,&z);
g[x].push_back({y,z});
g[y].push_back({x,z});
}
priority_queue<pair<long long,int> > pq;
pq.push({0,s});
for(int i = 0;i<=n;i++) dist[i] = INF;
dist[s] = 0;
while(!pq.empty()){
pair<long long,int> gag = pq.top();
pq.pop();
for(int i = 0;i<g[gag.second].size();i++){
int to = g[gag.second][i].first;
if(dist[to]>(-gag.first)+g[gag.second][i].second){
dist[to] = (-gag.first)+g[gag.second][i].second;
pq.push({-dist[to],to});
}
}
}
dfs(s);
if(all.size()>1) assert(0);
/*
for(int i = 0;i<all.size();i++){
memset(col,0,sizeof(col));
for(int j = 0;j<=n;j++) D[j] = INF;
mp.clear();
for(int j = 0;j<all[i].size()-1;j++) mp[{all[i][j],all[i][j+1]}] = mp[{all[i][j+1],all[i][j]}] = 1;
go(U);
}
cout<<ans<<endl;
*/
/*for(int i = 1;i<=n;i++){
cout<<i<<" "<<dist[i]<<endl;
}*/
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... |