Submission #1087585

#TimeUsernameProblemLanguageResultExecution timeMemory
1087585pqthangvCommuter Pass (JOI18_commuter_pass)C++11
31 / 100
245 ms37288 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define siz(v) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define FOR(i, a, b) for(int i = (a); i <= (b); i++) ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;} const int N = 2e5+5; const ll MOD = 1e9+7; const ll INF = 1e18; struct Edge{ int u,v; ll w; }; int n, m, S, T, X, Y; ll d[4][N], dp[2][N]; vector<pair<int,ll>> g[N]; vector<int> adj[N], topo; Edge E[N]; bool vis[N]; void Dijkstra(int id, int source) { priority_queue<pair<ll, int>> pq; for(int i = 1; i <= n; i++){ d[id][i] = (i == source ? 0 : INF); } pq.push(make_pair(0, source)); while(!pq.empty()){ pair<ll,int> e = pq.top(); pq.pop(); if(e.fi > d[id][e.se]) continue; int x = e.se; for(pair<int,ll> eq : g[x]){ int v = eq.fi; ll w = eq.se; if(d[id][v] > d[id][x] + w){ d[id][v] = d[id][x] + w; pq.push(make_pair(-d[id][v], v)); } } } return; } void get_topoOrder(int x){ vis[x] = true; for(int v : adj[x]){ if(!vis[v]) get_topoOrder(v); } dp[0][x] = dp[1][x] = INF; topo.push_back(x); return; } void solve() { cin >> n >> m; cin >> S >> T >> X >> Y; for(int i = 1; i <= m; i++){ int u,v,w; cin >> u >> v >> w; g[u].push_back(make_pair(v, w)); g[v].push_back(make_pair(u, w)); E[i] = {u, v, w}; } Dijkstra(0, S); Dijkstra(1, T); Dijkstra(2, X); Dijkstra(3, Y); for(int i = 1; i <= m; i++){ int u = E[i].u, v = E[i].v; if(d[0][u] + E[i].w + d[1][v] == d[0][T] || d[0][T] == d[1][u] + E[i].w + d[0][v]){ adj[u].push_back(v); adj[v].push_back(u); } } for(int i = 1; i <= n; i++){ sort(adj[i].begin(), adj[i].end()); adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end()); } get_topoOrder(S); reverse(topo.begin(), topo.end()); ll answer = d[2][Y]; for(int v : topo){ dp[0][v] = min(dp[0][v], d[2][v]); dp[1][v] = min(dp[1][v], d[3][v]); answer = min(answer, dp[0][v] + dp[1][v]); for(int x : adj[v]){ dp[0][x] = min(dp[0][x], dp[0][v]); dp[1][x] = min(dp[1][x], dp[1][v]); } } cout << answer <<"\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

Compilation message (stderr)

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