Submission #1144415

#TimeUsernameProblemLanguageResultExecution timeMemory
1144415arafatenokCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
501 ms40236 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #pragma ("reroll") #define skip continue; #define gold ios_base::sync_with_stdio(false);cin.tie(NULL); #define xa "\n" #define int long long #define all(a) a.begin(), a.end() #define pb push_back using namespace std; const int mod = 1e9 + 7; const int N = 2e5 + 7; const int MAX = 1e9; const int inf = 1e18; int gcd(int a, int b) { if (b == 0) return a; else if(a == 0) return b; else return gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } vector <pair < int, int > > g[N]; int n, m, dist[N]; int parent[N]; int x[N], y[N], w[N]; map < pair < int, int >, int > check; void dijkstra(int start) { for(int i = 1; i <= n; i++){ parent[i] = 0; dist[i] = inf; } set < pair < int ,int > > st; dist[start] = 0, st.insert({ 0, start }); while(st.size() > 0) { int v = (*st.begin()).second; st.erase(st.begin()); for (auto p : g[v]) { int to = p.first, w = p.second; if (dist[v] + w < dist[to]) { parent[to] = v; st.erase({ dist[to], to }); dist[to] = dist[v] + w; st.insert({ dist[to], to }); } } } } void solve() { cin >> n >> m; int s, t; cin >> s >> t; int u, v; cin >> u >> v; for(int i = 1; i <= m; i++){ cin >> x[i] >> y[i] >> w[i]; g[x[i]].pb({y[i], w[i]}); g[y[i]].pb({x[i], w[i]}); } dijkstra(s); int one = t, two = parent[t]; for(int i = 1; i <= n; i++){ g[i].clear(); } while(two != 0){ g[two].pb({one, 0}); g[one].pb({two, 0}); check[{one, two}] = 1; check[{two, one}] = 1; one = parent[one]; two = parent[two]; } for(int i = 1; i <= m; i++){ if(check[{x[i], y[i]}] == 0){ g[x[i]].pb({y[i], w[i]}); g[y[i]].pb({x[i], w[i]}); } } dijkstra(u); cout << dist[v]; } signed main() { gold; //freopen("pails.in", "r", stdin); //freopen("pails.out", "w", stdout); int t = 1; int ti = 1; //cin >> t; while (t--) { //cout << "Case " << ti << ": "; solve(); ti++; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...