Submission #611892

#TimeUsernameProblemLanguageResultExecution timeMemory
611892jame0313Price List (POI13_cen)C++17
20 / 100
3600 ms8588 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using ld = long double; using pll = pair<ll, ll>; // and so on vector<vector<int> > mp; bool vis[100001]; int vis2[100001]; bool vis3[100001]; ll dist[100001]; const ll INF = 1LL << 60; priority_queue<pll, vector<pll>, greater<pll> > pq; int N, M, S, A, B; void dijkstra() { for (int i = 1; i <= N; i++) dist[i] = INF; dist[S] = 0; pq.push({dist[S], S}); while (!pq.empty()) { auto [d, x] = pq.top(); pq.pop(); if (vis[x]) continue; vis[x] = true; vis2[x] = x; for (auto nx : mp[x]) { vis2[nx] = x; if (!vis[nx] && dist[nx] > dist[x] + A) { dist[nx] = dist[x] + A; pq.push({dist[nx], nx}); } } for (auto nx : mp[x]) { if(vis3[nx]&&vis[nx]) continue; vis3[nx] = true; for (auto nnx : mp[nx]) { if (vis2[nnx] == x) continue; vis2[nnx] = x; if (!vis[nnx] && dist[nnx] > dist[x] + B) { dist[nnx] = dist[x] + B; pq.push({dist[nnx], nnx}); } } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M >> S >> A >> B; mp.resize(N + 1); vector<int> costs; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; mp[a].push_back(b); mp[b].push_back(a); } dijkstra(); for (int i = 1; i <= N; i++) cout << dist[i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...