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>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
/*
const int MOD = ;
inline void mod(int &x) {
if(x >= MOD)
x -= MOD;
}
inline void add(int &x, int y) {
x += y;
mod(x);
}
inline void sub(int &x, int y) {
x += MOD - y;
mod(x);
}
inline void mul(int &x, int y) {
x = (1LL * x * y) % MOD;
}
*/
using namespace std;
const int INF = 1e9;
const int MAXN = (int) 1e5;
vector <int> g[MAXN + 1];
int dstA[MAXN + 1], dstB[MAXN + 1];
int n, m, k, a, b;
inline void bfsA() {
fill(dstA + 1, dstA + n + 1, INF);
queue <int> Q;
Q.push(k);
dstA[k] = 0;
while(Q.size()) {
int nod = Q.front();
Q.pop();
for(auto it : g[nod]) {
if(dstA[it] == INF) {
dstA[it] = dstA[nod] + 1;
Q.push(it);
}
}
}
}
set <int> mst[MAXN + 1];
vector <int> activ[MAXN + 1];
inline void bfsB() {
fill(dstB + 1, dstB + n + 1, INF);
queue <int> Q;
Q.push(k);
dstB[k] = 0;
while(Q.size()) {
int nod = Q.front();
Q.pop();
for(auto it : g[nod]) {
vector <int> cur;
for(auto itr : activ[it]) {
if(dstB[itr] != INF) {
continue;
}
if(mst[nod].find(itr) == mst[nod].end()) {
dstB[itr] = dstB[nod] + 1;
Q.push(itr);
}
else {
cur.push_back(itr);
}
}
swap(cur, activ[it]);
}
}
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k >> a >> b;
for(i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y), g[y].push_back(x);
mst[x].insert(y), mst[y].insert(x);
activ[x].push_back(y), activ[y].push_back(x);
}
bfsA();
bfsB();
for(i = 1; i <= n; i++) {
if(dstA[i] % 2 == 0) {
cout << min(1LL * b * dstA[i] / 2, 1LL * a * dstA[i]) << "\n";
}
else {
cout << min(1LL * dstB[i] * b, min(1LL * dstA[i] * a, 1LL * (dstA[i] / 2) * b + (dstA[i] & 1) * a)) << "\n";
}
}
//cin.close();
//cout.close();
return 0;
}
# | 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... |