Submission #745746

#TimeUsernameProblemLanguageResultExecution timeMemory
745746chanhchuong123Commuter Pass (JOI18_commuter_pass)C++14
15 / 100
2072 ms174736 KiB
#include <bits/stdc++.h> using namespace std; #define task "" #define fi first #define se second #define MASK(i) (1 << (i)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define BIT(mask, i) ((mask) >> (i) & 1) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i) template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int dx[] = {-1, 0, 0, +1}; const int dy[] = {0, -1, +1, 0}; const long long INF = 1e18; const int MAX = 100100; int n, m; int S, T; int U, V; long long dpU[MAX]; long long dpV[MAX]; long long d[4][MAX]; vector<pair<int, int>> adj[MAX]; void dijkstra(int t, int s) { priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq; for (int i = 1; i <= n; ++i) d[t][i] = INF; pq.push({0, s}); d[t][s] = 0; while (pq.size()) { long long dist = pq.top().fi; int u = pq.top().se; pq.pop(); if (dist != d[t][u]) continue; for (pair<int, int> &x: adj[u]) { int v = x.fi, w = x.se; if (minimize(d[t][v], dist + w)) pq.push({d[t][v], v}); } } } vector<int> topo; void dfs(int u) { for (pair<int, int> &x: adj[u]) { int v = x.fi, w = x.se; if (d[0][u] + w + d[1][v] == d[0][T]) dfs(v); } topo.push_back(u); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> n >> m; cin >> S >> T; cin >> U >> V; for (int i = 1; i <= m; ++i) { int u, v, c; cin >> u >> v >> c; adj[u].push_back({v, c}); adj[v].push_back({u, c}); } dijkstra(0, S); dijkstra(1, T); dijkstra(2, U); dijkstra(3, V); memset(dpU, 0x3f, sizeof dpU); memset(dpV, 0x3f, sizeof dpV); dfs(S); reverse(all(topo)); long long ans = d[2][V]; for (int i: topo) { minimize(dpU[i], d[2][i]); minimize(dpV[i], d[3][i]); minimize(ans, dpU[i] + d[3][i]); minimize(ans, dpV[i] + d[2][i]); for (pair<int, int> &x: adj[i]) { int j = x.fi, w = x.se; if (d[0][i] + w + d[1][j] == d[0][T]) minimize(dpU[j], dpU[i]), minimize(dpV[j], dpV[i]); } } cout << ans; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:65:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:66:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...