# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103529 | Alliance | Commuter Pass (JOI18_commuter_pass) | C++14 | 1071 ms | 28964 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.
// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 1e5+10;
const ll MOD = 1e9+7;
using namespace std;
vector<pair<int,ll>> g[MAX_N];
ll dis[MAX_N];
int mark[MAX_N];
vector<int> p[MAX_N];
int s,t,u,v;
vector<int> vers;
int n,m;
void dij()
{
for(int i = 1;i<=n;++i)
dis[i] = 1e18;
for(auto x:vers)
dis[x] = 0;
set<pair<ll,int>> st;
for(int i = 1;i<=n;++i)
st.insert({dis[i],i});
while(st.size())
{
int v = (*st.begin()).second;
st.erase(st.begin());
for(auto x:g[v])
{
ll u = x.first;
int w = x.second;
ll d = dis[v]+w;
if (dis[u]==d)
p[u].push_back(v);
else if (dis[u]>d)
{
st.erase({dis[u],u});
dis[u] = d;
st.insert({dis[u],u});
p[u].clear();
p[u].push_back(v);
}
}
}
}
void dfs(int v)
{
mark[v]++;
vers.push_back(v);
for(auto x:p[v])
{
if (!mark[x])
dfs(x);
}
}
void make_zero(int u,int v)
{
for(int i = 0;i<g[u].size();++i)
{
if (g[u][i].first==v)
g[u][i].second = 0;
}
for(int i = 0;i<g[v].size();++i)
{
if (g[v][i].first==u)
g[v][i].second = 0;
}
}
int main()
{
cin >> n >> m >> s >> t >> u >> v;
for(int i = 0;i<m;++i)
{
int a,b,w;
scanf("%d%d%d",&a,&b,&w);
g[a].push_back({b,w});
g[b].push_back({a,w});
}
vers.push_back(s);
dij();
vers.clear();
if (s==u)
{
dfs(t);
dij();
cout << dis[v];
return 0;
}
vector<int> path;
int now = t;
while(p[now].size())
{
path.push_back(now);
now = p[now][0];
}
path.push_back(now);
for(int i = 0;i<path.size()-1;++i)
make_zero(path[i],path[i+1]);
vers.push_back(u);
dij();
cout << dis[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... |