Submission #1064551

#TimeUsernameProblemLanguageResultExecution timeMemory
1064551EkinOnalPrice List (POI13_cen)C++17
100 / 100
52 ms16356 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; #define f first #define s second #define LOGN 20 const ll MOD = 998244353; const ll MAXN = 1e5 + 100; #define int long long vector<vector<int>> graph, graph2; int dist1[MAXN], dist2[MAXN], vis[MAXN]; signed main() { fast int n, m, k, a, b; cin >> n >> m >> k >> a >> b; graph = vector<vector<int>>(n+1, vector<int>()); for (int i = 0; i < m; i++) { int q, p; cin >> q >> p; graph[q].push_back(p); graph[p].push_back(q); } graph2 = graph; for (int i = 1; i <= n; i++) sort(graph[i].begin(), graph[i].end()); queue<pair<int,int>> q; q.push({0, k}); for (int i = 0; i <= n; i++) dist1[i] = dist2[i] = 1e15; dist2[k] = dist1[k] = 0; while (!q.empty()) { int node = q.front().s; q.pop(); if (vis[node]) continue; vis[node] = true; for (auto u : graph[node]) { if (dist1[u] > dist1[node] + 1) { dist1[u] = dist1[node] + 1; q.push({dist1[u], u}); } } } for (int i = 0; i <= n; i++) vis[i] = false; q.push({0, k}); vis[k] = true; while (!q.empty()) { int node = q.front().s; q.pop(); for (auto node1 : graph[node]) { for (auto node2 : graph2[node1]) { if (vis[node2]) continue; /* if (*lower_bound(graph[node].begin(), graph[node].end(), node2) == node2) continue; */ if (binary_search(graph[node].begin(), graph[node].end(), node2)) continue; dist2[node2] = dist2[node] + 1; vis[node2] = true; q.push({dist2[node2], node2}); } vector<int> v; for (auto node2 : graph2[node1]) if (!vis[node2]) v.push_back(node2); swap(graph2[node1], v); } } for (int i = 1; i <= n; i++) { if (dist1[i] % 2 == 0) cout << min(dist1[i] * a, (dist1[i] / 2) * b) << "\n"; else cout << min({dist1[i] * a, dist2[i] * b, (dist1[i] / 2) * b + a}) << "\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...