Submission #1087582

#TimeUsernameProblemLanguageResultExecution timeMemory
1087582MinhKienCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
216 ms24776 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; #define int long long const int N = 1e5 + 10; #define ll long long #define li pair <ll, int> int n, m, a, b, c, d; int x, y; ll k; vector <li> v[N]; ll disA[N], disB[N], disC[N], disD[N]; void dijkstra(int s, ll dis[]) { fill_n(dis, N, 4e18); dis[s] = 0; priority_queue < li, vector <li>, greater <li> > q; q.push(li(0, s)); while (!q.empty()) { li p = q.top(); q.pop(); int u = p.second; ll w = p.first; if (dis[u] < w) continue; for (li z: v[u]) { if (z.first + w < dis[z.second]) { dis[z.second] = z.first + w; q.push(li(dis[z.second], z.second)); } } } } void pre() { dijkstra(a, disA); dijkstra(b, disB); dijkstra(c, disC); dijkstra(d, disD); } ll dp[2][N], best = 4e18; bool vis[N]; void dfs(int s) { vis[s] = true; dp[0][s] = dp[1][s] = 4e18; for (li i: v[s]) { int z = i.second; if (disA[s] + disB[z] + i.first != disA[b]) continue; if (!vis[z]) { dfs(z); } dp[0][s] = min(dp[0][s], dp[0][z]); dp[1][s] = min(dp[1][s], dp[1][z]); } best = min(best, disC[s] + dp[1][s]); best = min(best, dp[0][s] + disD[s]); dp[0][s] = min(dp[0][s], disC[s]); dp[1][s] = min(dp[1][s], disD[s]); } void solve() { best = disC[d]; dfs(a); cout << best << "\n"; } signed main() { if (fopen("bus.inp", "r")) { freopen("bus.inp", "r", stdin); freopen("bus.out", "w", stdout); } cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); cin >> n >> m >> a >> b >> c >> d; for (int i = 1; i <= m; ++i) { cin >> x >> y >> k; v[x].push_back(li(k, y)); v[y].push_back(li(k, x)); } pre(); solve(); return 0; }

Compilation message (stderr)

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