제출 #956320

#제출 시각아이디문제언어결과실행 시간메모리
956320serifefedartar새로운 문제 (POI13_cen)C++17
90 / 100
69 ms14876 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; vector<vector<int>> graph, graph2; int dist1[MAXN], dist2[MAXN], vis[MAXN]; int 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] = 1e9; 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; 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...