1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
| #include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 210000,MAXM = 210000;
struct Graph{
int to[MAXM],nex[MAXM],pre[MAXM];
int fir[MAXN];int ecnt;
Graph(){
ecnt = 1;
}
void addedge(int u,int v){
int e = ecnt;
pre[fir[u]] = e;
to[e] = v,nex[e] = fir[u],pre[e] = 0;
fir[u] = e;
ecnt++;
}
void deledge(int x,int e){
int n = nex[e],p = pre[e];
if(!p) fir[x] = n;
nex[p] = n,pre[n] = p;
}
}A,B;
int n,m,k,a,b;
long long ans[MAXN];
long long dis[MAXN];
queue<int> q;
void init(){
scanf("%d %d %d %d %d",&n,&m,&k,&a,&b);
int u,v;
for(int i = 1;i<=m;i++){
scanf("%d %d",&u,&v);
A.addedge(u,v),A.addedge(v,u);
B.addedge(u,v),B.addedge(v,u);
}
}
void bfs1(){
while(!q.empty()) q.pop();
for(int i = 1;i<=n;i++) dis[i] = 1000000;
dis[k] = 0;q.push(k);
while(!q.empty()){
int nown = q.front();q.pop();
for(int nowe = A.fir[nown];nowe;nowe = A.nex[nowe]){
int v = A.to[nowe];
if(dis[v] > dis[nown] + 1){
dis[v] = dis[nown] + 1;
q.push(v);
}
}
}
for(int i = 1;i<=n;i++)
ans[i] = min(dis[i] * a,(dis[i]/2) * b + (dis[i]%2) * a);
}
void bfs2(){
static bool vis[MAXN];
while(!q.empty()) q.pop();
for(int i = 1;i<=n;i++)
dis[i] = 1000000;
dis[k] = 0;q.push(k);
while(!q.empty()){
int nown = q.front();q.pop();
vis[nown] = 1;
for(int e1 = A.fir[nown];e1;e1 = A.nex[e1]){
int v1 = A.to[e1];
vis[v1] = 1;
}
for(int e1 = A.fir[nown];e1;e1 = A.nex[e1]){
int v1 = A.to[e1];
for(int e2 = B.fir[v1];e2;e2 = B.nex[e2]){
int v2 = B.to[e2];
if(!vis[v2]){
// printf(" v2:%d\n",v2);
if(dis[v2] > dis[nown] + 1){
dis[v2] = dis[nown] + 1;
q.push(v2);
}
B.deledge(v1,e2);
}
}
}
for(int e1 = A.fir[nown];e1;e1 = A.nex[e1]){
int v1 = A.to[e1];
vis[v1] = 0;
}
vis[nown] = 0;
}
for(int i = 1;i<=n;i++)
ans[i] = min(ans[i],dis[i] * b);
}
void solve(){
memset(ans,0x3f,sizeof(ans));
bfs1();
bfs2();
for(int i = 1;i<=n;i++){
printf("%lld\n",ans[i]);
}
}
int main(){
init();
solve();
return 0;
}
|