제출 #1167675

#제출 시각아이디문제언어결과실행 시간메모리
1167675herissonwowCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
208 ms14552 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #define ll long long #define ld long double #define en exit(0); #define pb push_back #define fi first #define se second using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1e5+5; const ll INF = 1e18+5; vector<pair<int,int> > g[N]; bool marked[N]; vector<ll> dijkstra(int st, int n) { vector<ll> dist(n+1,INF); vector<bool> vis(n+1); priority_queue<pair<ll,int> > q; dist[st]=0; q.push({0,st}); while(!q.empty()) { int u = q.top().se; q.pop(); if(vis[u]) continue; vis[u]=1; for(auto p:g[u]) { ll nwd = dist[u]+p.se; if(nwd<dist[p.fi]) { dist[p.fi]=nwd; q.push({-nwd,p.fi}); } } } return dist; } int main() { //ios_base()::sync_with_stdio(false); cin.tie(0); int n, m, s, u, t, v; cin >> n >> m >> s >> u >> t >> v; for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; g[a].push_back({b,c}); g[b].push_back({a,c}); } vector <long long> dS = dijkstra(s, n); vector <long long> dU = dijkstra(u, n); vector <long long> dV = dijkstra(v, n); int TOT = dS[t]; for(int i = 1; i <= n; i++){ if(dS[i]+dV[i]==TOT) marked[i]=1; } ll res = INF; for(int i = 1; i <= n; i++){ if(marked[i]){ res = min(res, dV[i]); } } cout << res; 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...