This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 21
const ll MOD = 1e9 + 7;
const ll MAXN = 1e5 + 100;
vector<vector<int>> graph;
int vis[MAXN], dist[MAXN];
int main() {
fast;
int N, M, K, A, B, u, v;
cin >> N >> M >> K >> A >> B;
graph = vector<vector<int>>(N+1, vector<int>());
for (int i = 0; i < M; i++) {
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
queue<int> q;
q.push(K);
while (!q.empty()) {
int node = q.front();
q.pop();
vis[node] = true;
for (auto u : graph[node]) {
if (!vis[u]) {
dist[u] = dist[node] + 1;
vis[u] = true;
q.push(u);
}
}
}
for (int i = 1; i <= N; i++)
cout << min(dist[i] * A, dist[i] / 2 * B + (dist[i] % 2) * A) << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |