Submission #250701

#TimeUsernameProblemLanguageResultExecution timeMemory
250701mat_vCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
603 ms23992 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<ll,ll> #define N 100005 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n,m; int s,t; int u,v; vector<pii> graf[N]; ll dist[N][4]; void djikstra(int x, int idx){ priority_queue<pii> pq; pq.push({0,x}); ff(i,1,n){ dist[i][idx] = 1e8; dist[i][idx] *= dist[i][idx]; } dist[x][idx] = 0; while(!pq.empty()){ pii sta = pq.top(); pq.pop(); int tr = sta.yy; ll duz = -sta.xx; if(dist[tr][idx] != duz)continue; for(auto c:graf[tr]){ if(dist[c.xx][idx] > duz + c.yy){ dist[c.xx][idx] = duz + c.yy; pq.push({-dist[c.xx][idx], c.xx}); } } } } int gidx; ll dp[N][2]; bool bio[N][2]; ll resi(int x){ if(bio[x][gidx])return dp[x][gidx]; bio[x][gidx] = 1; dp[x][gidx] = dist[x][3]; for(auto c:graf[x]){ if(dist[c.xx][gidx] + c.yy == dist[x][gidx]){ dp[x][gidx] = min(dp[x][gidx], resi(c.xx)); } } return dp[x][gidx]; } void init(int x){ bio[x][gidx] = 1; dp[x][gidx] = dist[x][3]; ff(i,1,n){ if(!bio[i][gidx])dp[i][gidx] = resi(i); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> s >> t >> u >> v; ff(i,0,m - 1){ ll a,b,c; cin >> a >> b >> c; graf[a].pb({b,c}); graf[b].pb({a,c}); } djikstra(s,0); djikstra(t,1); djikstra(u,2); djikstra(v,3); gidx = 0; init(s); gidx = 1; init(t); ll res = dist[v][2]; ff(i,1,n){ if(!(dist[i][0] + dist[i][1] == dist[t][0]))continue; res = min(res, dist[i][2] + min(dp[i][0], dp[i][1])); } cout << res << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...