제출 #913952

#제출 시각아이디문제언어결과실행 시간메모리
913952a_l_i_r_e_z_aCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
376 ms33848 KiB
// In the name of God // Hope is last to die #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define pb push_back #define S second #define F first #define mp make_pair #define smax(x, y) (x) = max((x), (y)) #define smin(x, y) (x) = min((x), (y)) #define all(x) (x).begin(), (x).end() #define len(x) ((int)(x).size()) const int maxn = 1e5 + 5; const ll inf = 1e18 + 7; ll n, m, s, t, x, y, ans = inf, d[maxn][3], dp[maxn][3]; set<pll> st; vector<pll> adj[maxn]; vector<int> g[maxn]; bool mark[maxn]; void dij(int v, int ind){ st.clear(); st.insert(mp(0, v)); d[v][ind] = 0; while(st.size()){ ll v = (*st.begin()).S, dist = (*st.begin()).F; st.erase(st.begin()); for(auto [u, w]: adj[v]){ if(d[v][ind] + w < d[u][ind]){ st.erase(mp(d[u][ind], u)); d[u][ind] = d[v][ind] + w; st.insert(mp(d[u][ind], u)); } } } } void dfs(int v){ mark[v] = 1; dp[v][1] = dp[v][2] = inf; for(auto u: g[v]){ if(!mark[u]) dfs(u); smin(dp[v][1], dp[u][1]); smin(dp[v][2], dp[u][2]); } if(dp[v][1] == inf){ if(v == t){ dp[v][1] = d[v][1]; dp[v][2] = d[v][2]; } } else{ smin(dp[v][1], d[v][1]); smin(dp[v][2], d[v][2]); } smin(ans, d[v][1] + dp[v][2]); smin(ans, d[v][2] + dp[v][1]); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(d, 63, sizeof d); cin >> n >> m >> s >> t >> x >> y; for(int i = 1; i <= m; i++){ int u, v, w; cin >> u >> v >> w; adj[u].pb(mp(v, w)); adj[v].pb(mp(u, w)); } dij(s, 0); dij(x, 1); dij(y, 2); for(int i = 1; i <= n; i++){ for(auto [u, w]: adj[i]){ if(d[i][0] + w == d[u][0]) g[i].pb(u); } } dfs(s); cout << min(ans, d[y][1]) << '\n'; return 0; }

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

commuter_pass.cpp: In function 'void dij(int, int)':
commuter_pass.cpp:34:33: warning: unused variable 'dist' [-Wunused-variable]
   34 |         ll v = (*st.begin()).S, dist = (*st.begin()).F;
      |                                 ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...