Submission #1241928

#TimeUsernameProblemLanguageResultExecution timeMemory
1241928sunitCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
2098 ms75232 KiB
#include<bits/stdc++.h> #define int long long #define bl bool #define db double #define fl float #define st string #define pb push_back #define pf push_front #define is insert #define endl "\n" #define pba pop_back #define pfr pop_front #define ub upper_bound #define lb lower_bound #define fi first #define se second #define FOR(i, l, r, st) for(int i = l; i <= r; i += st) #define FOS(i, l, r, sl) for(int i = l; i >= r; i -= sl) #define mii map<int, int> #define us unordered_set #define pii pair<int, int> #define vt vector using namespace std; const int maxn = 1e6 + 5; const int mod = 1e9 + 7; void suncuti() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } void fre() { if(fopen("name.INP", "r")) { freopen("name.INP", "r", stdin); freopen("name.OUT", "w", stdout); } } int n, m, A, B, C, D; vt<pii>kt[maxn]; int trace[maxn]; map<pii, int>seen; int dp[maxn]; void dij() { fill(dp, dp + maxn, 1e18); memset(trace, -1, sizeof(trace)); dp[A] = 0; priority_queue<pii, vt<pii>, greater<pii>>q; q.push({0, A}); while(q.size()) { int c = q.top().fi, u = q.top().se; q.pop(); if(c > dp[u]) continue; for(auto v : kt[u]) { int cost = v.se + dp[u]; if(cost < dp[v.fi]) { dp[v.fi] = cost; trace[v.fi] = u; q.push({dp[v.fi], v.fi}); } } } } vt<int>path; void bfs() { fill(dp, dp + maxn, 1e18); dp[C] = 0; deque<int>d; d.pf(C); while(d.size()) { int u = d.front(); d.pfr(); for(auto v : kt[u]) { int cost = dp[u]; if(seen[{v.fi, u}] || seen[{u, v.fi}]) cost = cost; else cost = cost + v.se; if(cost < dp[v.fi]) { dp[v.fi] = cost; if(!cost) d.pf(v.fi); else d.pb(v.fi); } } } } main() { suncuti(); cin >> n >> m; cin >> A >> B; cin >> C >> D; FOR(i, 1, m, 1) { int u, v, w; cin >> u >> v >> w; kt[u].pb({v, w}); kt[v].pb({u, w}); } dij(); int kit = B; while(kit != -1) { path.pb(kit); kit = trace[kit]; } reverse(path.begin(), path.end()); FOR(i, 1, path.size() - 1, 1) { // cout << path[i] << " "; seen[{path[i], path[i - 1]}] = seen[{path[i - 1], path[i]}] = 1; } bfs(); cout << dp[D]; }

Compilation message (stderr)

commuter_pass.cpp:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   96 | main() {
      | ^~~~
commuter_pass.cpp: In function 'void fre()':
commuter_pass.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen("name.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("name.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...