제출 #678568

#제출 시각아이디문제언어결과실행 시간메모리
678568hollwo_pelwCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
343 ms21020 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/trie_policy.hpp> // #include <ext/rope> using namespace std; // using namespace __gnu_cxx; // using namespace __gnu_pbds; void Hollwo_Pelw(); signed main(){ #ifndef hollwo_pelw_local if (fopen(".inp", "r")) assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout)); #else using namespace chrono; auto start = steady_clock::now(); #endif cin.tie(0), cout.tie(0) -> sync_with_stdio(0); int testcases = 1; // cin >> testcases; for (int test = 1; test <= testcases; test++){ // cout << "Case #" << test << ": "; Hollwo_Pelw(); } #ifdef hollwo_pelw_local auto end = steady_clock::now(); cout << "\nExecution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl; #endif } #define int long long const int N = 1e5 + 5; int n, m, S, T, U, V; vector<pair<int, int>> adj[N]; int ds[N], dt[N], du[N], dv[N], fu[N], fv[N]; void dijkstra(int s, int *d) { fill(d + 1, d + n + 1, 1e18); priority_queue<pair<int, int>> pq; pq.emplace(d[s] = 0, s); while (!pq.empty()) { auto [D, u] = pq.top(); pq.pop(), D = -D; if (d[u] != D) continue; for (auto [v, w] : adj[u]) { if (d[v] > D + w) pq.emplace(- (d[v] = D + w), v); } } } void Hollwo_Pelw(){ cin >> n >> m >> S >> T >> U >> V; for (int u, v, w; m --; ) { cin >> u >> v >> w; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } dijkstra(S, ds); dijkstra(T, dt); dijkstra(U, du); dijkstra(V, dv); vector<pair<int, int>> ord; for (int i = 1; i <= n; i++) { if (ds[i] + dt[i] == ds[T]) { // in path ord.emplace_back(dt[i], i); } } sort(ord.begin(), ord.end()); fill(fu + 1, fu + n + 1, 1e18); fill(fv + 1, fv + n + 1, 1e18); int res = du[V]; for (auto [_, x] : ord) { fu[x] = du[x], fv[x] = dv[x]; for (auto [y, w] : adj[x]) { if (dt[y] + w == dt[x]) { fu[x] = min(fu[x], fu[y]); fv[x] = min(fv[x], fv[y]); } } res = min({res, fu[x] + dv[x], fv[x] + du[x]}); } cout << res << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...