제출 #701793

#제출 시각아이디문제언어결과실행 시간메모리
701793mychecksedadCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
406 ms52328 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], dp[N][2]; vector<array<ll, 3>> g[N]; vector<bool> vis; vector<array<bool, 2>> vis2; 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]){ int 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); } } } } priority_queue<array<ll, 4>> q2; ll ans = LONG_LONG_MAX; for(int i = 1; i <= n; ++i) dp[i][0] = dp[i][1] = LONG_LONG_MAX; dp[x][0] = 0; q2.push({0, x, 0, 0}); vis2.resize(n + 1, {0, 0}); while(!q2.empty()){ int v = q2.top()[1], tp = q2.top()[2], dir = q2.top()[3]; q2.pop(); int tt = tp>0; if(vis2[v][tt]) continue; vis2[v][tt] = 1; for(auto U: g[v]){ int u = U[0], w = U[1]; if(good[U[2]][0] == u && good[U[2]][1] == v && tp != 2 && dir != 2){ if(!vis2[u][tt] && dp[u][1] > dp[v][tt]){ dp[u][1] = dp[v][tt]; q2.push({-dp[u][1], u, 1, 1}); } }else if(good[U[2]][0] == v && good[U[2]][1] == u && tp != 2 && dir != 1){ if(!vis2[u][tt] && dp[u][1] > dp[v][tt]){ dp[u][1] = dp[v][tt]; q2.push({-dp[u][1], u, 1, 2}); } }else{ if(!vis2[u][tt] && dp[u][tt] > dp[v][tt] + w){ dp[u][tt] = dp[v][tt] + w; q2.push({-dp[u][tt], u, (tp >= 1 ? 2 : 0)}); } } } } ans = min(ans, min(dp[y][0], dp[y][1])); 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; }

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:98:14: warning: unused variable 'aa' [-Wunused-variable]
   98 |   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...