이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |