# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103527 | Alliance | Commuter Pass (JOI18_commuter_pass) | C++14 | 1114 ms | 28780 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);
}
}
int main()
{
cin >> n >> m >> s >> t >> u >> v;
if (s!=u)
exit(1);
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();
dfs(t);
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... |