제출 #1089830

#제출 시각아이디문제언어결과실행 시간메모리
1089830MinhKienCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
2073 ms26580 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; #define ll long long #define li pair <ll, int> const int N = 1e5 + 10; int n, m, x, y; int a, b, c, d; ll cost, A[N], B[N], C[N], D[N]; vector <li> v[N]; void dijkstra(int st, ll dis[]) { fill_n(dis, n + 1, 1e17); dis[st] = 0; priority_queue < li, vector <li>, greater <li> > q; q.push(li(0, st)); while (!q.empty()) { li p = q.top(); q.pop(); int u = p.second; ll w = p.first; if (w > dis[u]) continue; for (li z: v[u]) { if (z.first + w < dis[z.second]) { dis[z.second] = z.first + w; q.push(li(dis[z.second], z.second)); } } } } void pre() { dijkstra(a, A); dijkstra(b, B); dijkstra(c, C); dijkstra(d, D); } ll best = 1e17; ll dp[2][N]; void dfs(int s, int p) { dp[0][s] = dp[1][s] = 1e17; for (li z: v[s]) { if (A[s] + z.first + B[z.second] == A[b]) { if (z.second == p) continue; dfs(z.second, s); dp[0][s] = min(dp[0][z.second], dp[0][s]); dp[1][s] = min(dp[1][z.second], dp[1][s]); } best = min(best, dp[0][s] + C[s]); best = min(best, dp[1][s] + D[s]); dp[0][s] = min(dp[0][s], D[s]); dp[1][s] = min(dp[1][s], C[s]); } } void solve() { best = C[d]; dfs(a, -1); cout << best << "\n"; } int main() { cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false); cin >> n >> m; cin >> a >> b >> c >> d; while (m--) { cin >> x >> y >> cost; v[x].push_back(li(cost, y)); v[y].push_back(li(cost, x)); } pre(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...