Submission #745741

#TimeUsernameProblemLanguageResultExecution timeMemory
745741chanhchuong123Commuter Pass (JOI18_commuter_pass)C++14
0 / 100
272 ms21328 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]; vector<int> g[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}); } } } void dfsCalc(int u, long long &ans) { minimize(dpU[u], d[2][u]); minimize(dpV[u], d[3][u]); minimize(ans, dpU[u] + d[3][u]); minimize(ans, dpV[u] + d[2][u]); for (int v: g[u]) { minimize(dpU[v], dpU[u]); minimize(dpV[v], dpV[u]); dfsCalc(v, ans); } } 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); for (int i = 1; i <= n; ++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]) g[i].push_back(j); } } memset(dpU, 0x3f, sizeof dpU); memset(dpV, 0x3f, sizeof dpV); long long ans = d[2][V]; dfsCalc(1, ans); cout << ans; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:69:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:70:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   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...