Submission #218922

#TimeUsernameProblemLanguageResultExecution timeMemory
218922PeppaPigOlympic Bus (JOI20_ho_t4)C++14
5 / 100
1090 ms2808 KiB
#include <bits/stdc++.h> #define long long long #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 205; const int M = 5e4+5; int n, m; vector<pii> g[N]; array<int, 4> E[M]; long dp[N]; priority_queue<pii, vector<pii>, greater<pii> > Q; long dijkstra(int s, int e, int i) { fill_n(dp, N, 1e18); Q.emplace(dp[s] = 0, s); while(!Q.empty()) { pii u = Q.top(); Q.pop(); if(dp[u.y] != u.x) continue; for(pii v : g[u.y]) { if(v.y == i) continue; if(u.x + E[v.y][2] < dp[v.x]) Q.emplace(dp[v.x] = u.x + E[v.y][2], v.x); } if(u.y == E[i][1] && u.x + E[i][2] < dp[E[i][0]]) Q.emplace(dp[E[i][0]] = u.x + E[i][2], E[i][0]); } return dp[e]; } int main() { scanf("%d %d", &n, &m); for(int i = 1, a, b, c, d; i <= m; i++) { scanf("%d %d %d %d", &a, &b, &c, &d); E[i] = {a, b, c, d}; g[a].emplace_back(b, i); } long ans = min((long)1e18, dijkstra(1, n, 0) + dijkstra(n, 1, 0)); for(int i = 1; i <= m; i++) ans = min(ans, dijkstra(1, n, i) + dijkstra(n, 1, i) + E[i][3]); if(ans >= 1e18) printf("-1\n"); else printf("%lld\n", ans); return 0; }

Compilation message (stderr)

ho_t4.cpp: In function 'int main()':
ho_t4.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
ho_t4.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d", &a, &b, &c, &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...