제출 #1108147

#제출 시각아이디문제언어결과실행 시간메모리
1108147chaoslongCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
249 ms30472 KiB
// Calm down. // Think three times, code twice. #include "bits/stdc++.h" #define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a) #define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);) #define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a) #define st first #define nd second #define ll long long #define ull unsigned long long #define pii pair <ll,int> #define pll pair <ll,ll> #define piii pair <ll,pii> #define vi vector <int> #define pb push_back #define mp make_pair #define all(x) begin(x),end(x) #define mask(i) (1LL << (i)) #define bit(x, i) (((x) >> (i)) & 1) #define bp __builtin_popcountll #define file "test" using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; // 998244353 const ll oo = 1e18; ll ans; int n, m, s, t, u, v; vector<pii> a[N]; ll du[N], dv[N]; void xuly(int bd, ll d[]) { priority_queue<pii, vector<pii>, greater<pii>> q; q.push({0, bd}); d[bd] = 0; while(q.size()) { int u = q.top().nd; ll du = q.top().st; q.pop(); if(du < d[u]) continue; for(pii e: a[u]) { int v = e.nd; ll dv = e.st; if(du + dv < d[v]) { d[v] = du + dv; q.push({d[v], v}); } } } } void xuly2(int bd, int kt) { vector<ll> d(n + 5, oo); vector<vector<ll>> dp(2, vector<ll>(n+5, oo)); priority_queue<piii, vector<piii>, greater<piii>> q; q.push({0, {bd, 0}}); d[bd] = 0; dp[0][bd] = du[bd]; dp[1][bd] = dv[bd]; while(q.size()) { int u = q.top().nd.st, par = q.top().nd.nd; ll dist = q.top().st; q.pop(); if(d[u] < dist) continue; for(pii e: a[u]) { int v = e.nd; ll distv = e.st; if(dist + distv < d[v]) { d[v] = dist + distv; dp[0][v] = min(dp[0][u], du[v]); dp[1][v] = min(dp[1][u], dv[v]); q.push({d[v], {v, u}}); } else if(dist + distv == d[v]) { if(min(dp[0][u], du[v]) + min(dp[1][u], dv[v]) <= dp[0][v] + dp[1][v]) { dp[0][v] = min(dp[0][u], du[v]); dp[1][v] = min(dp[1][u], dv[v]); } } } } // cout << dp[0][kt] << " " << dp[1][kt] << "\n"; ans = min(ans, dp[0][kt] + dp[1][kt]); } void to_nho_cau() { cin >> n >> m >> s >> t >> u >> v; forr(i, 1, m) { int u, v; ll val; cin >> u >> v >> val; a[u].pb({val, v}); a[v].pb({val, u}); } memset(du, 63, sizeof du); memset(dv, 63, sizeof dv); xuly(u, du); xuly(v, dv); ans = du[v]; xuly2(s, t); xuly2(t, s); cout << ans << "\n"; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); #ifdef LOCAL freopen(file".inp","r",stdin); freopen(file".out","w",stdout); #endif int t = 1; //cin >> t; while(t--) to_nho_cau(); } /* 1.self check: 2.long long 3.size of array 4.code for testing 5.initializing 6.modulo number */ /** ∧__∧ (`•ω• )づ__∧ (つ  /( •ω•。) しーJ (nnノ) pat pat **/ /** /\_/\ * (= ._.) * / >☕ \>💻 **/

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

commuter_pass.cpp:116:9: warning: "/*" within comment [-Wcomment]
  116 | /**  /\_/\
      |          
commuter_pass.cpp: In function 'void xuly2(int, int)':
commuter_pass.cpp:56:32: warning: unused variable 'par' [-Wunused-variable]
   56 |         int u = q.top().nd.st, par = q.top().nd.nd; ll dist = q.top().st; q.pop();
      |                                ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...