Submission #701790

#TimeUsernameProblemLanguageResultExecution timeMemory
701790mychecksedadCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
283 ms43048 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define all(x) x.begin(), x.end() const int N = 1e6+100, M = 1e5+10, K = 20; int n, m, s, t, x, y; ll d[N]; vector<array<ll, 3>> g[N]; vector<bool> vis; vector<array<int, 2>> good; void solve(){ cin >> n >> m >> s >> t >> x >> y; for(int i = 0; i < m; ++i){ int u, v, w; cin >> u >> v >> w; g[u].pb({v, w, i}); g[v].pb({u, w, i}); } vis.resize(n + 1); good.resize(m); priority_queue<pair<ll, int>> q; q.push({0, s}); for(int i = 1; i <= n; ++i) d[i] = i == s ? 0 : LONG_LONG_MAX; while(!q.empty()){ int v = q.top().second; q.pop(); if(vis[v]) continue; vis[v] = 1; for(auto U: g[v]){ ll u = U[0], w = U[1]; if(!vis[u] && d[u] > d[v] + w){ d[u] = d[v] + w; q.push({-d[u], u}); } } } queue<int> Q; Q.push(t); fill(all(vis), 0); vis[t] = 1; while(!Q.empty()){ int v = Q.front(); Q.pop(); for(auto U: g[v]){ ll u = U[0], w = U[1]; if(d[u] == d[v] - w){ good[U[2]] = {v, u}; if(!vis[u]){ vis[u] = 1; Q.push(u); } } } } ll ans = LONG_LONG_MAX; for(int rep = 0; rep < 2; ++rep){ for(int i = 1; i <= n; ++i) d[i] = LONG_LONG_MAX; d[x] = 0; q.push({0, x}); fill(all(vis), 0); while(!q.empty()){ int v = q.top().second; q.pop(); if(vis[v]) continue; vis[v] = 1; for(auto U: g[v]){ ll u = U[0], w = U[1]; if(good[U[2]][rep] == v && good[U[2]][rep^1] == u) w = 0; if(!vis[u] && d[u] > d[v] + w){ d[u] = d[v] + w; q.push({-d[u], u}); } } } ans = min(ans, d[y]); } cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:52:26: warning: narrowing conversion of 'u' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   52 |         good[U[2]] = {v, u};
      |                          ^
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:87:14: warning: unused variable 'aa' [-Wunused-variable]
   87 |   int T = 1, aa;
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...