This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3,unroll-loops,Ofast")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define MAX 200007
#define pb push_back
#define mp make_pair
#define int long long
#define f first
#define s second
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define vpii vector<pair<int,int>>
const int mod = 1e9+7;
const int INF = 1e18;
// myMap.begin()->first : key
// myMap.begin()->second : value
int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;;b>>=1;}return ans;}
int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}
int sum(int a,int b){return ((a%mod)+(b%mod))%mod;}
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
void solve(){
int n,m,k,a,b; cin>>n>>m>>k>>a>>b;
vector<vi> graph(n+5);
for(int i=0;i<m;i++){
int x,y; cin>>x>>y;
graph[x].pb(y); graph[y].pb(x);
}
vector<vi> graph2=graph;
for(int i=1;i<=n;i++) sort(graph[i].begin(),graph[i].end());
// vector<vi> graph2=adj;
vi dist1(n+5,INF),dist2(n+5,INF);
dist1[k]=dist2[k]=0;
vi vis(n+5);
queue<int> q; q.push(k);
while(q.size()){
auto node = q.front();
q.pop();
if(vis[node]) continue;
vis[node]=true;
for(auto u : graph[node]){
// if(vis[u]) continue;
if(dist1[u]>dist1[node]+1)
{q.push(u); dist1[u]=dist1[node]+1;}
}
}
vis=vi(n+5);
vis[k]=true; q.push(k);
while(q.size()){
int node = q.front();
q.pop();
// if(dist[node.s]!=node.f) continue;
for(auto node1 : graph[node]){
for(auto node2 : graph2[node1]){
if(vis[node2]) continue;
if (binary_search(graph[node].begin(), graph[node].end(), node2))
continue;
dist2[node2]=dist2[node]+1;
vis[node2]=true;
q.push(node2);
}
vi v;
for(auto node2:graph2[node1]){
if(!vis[node2]) v.pb(node2);
}
swap(graph2[node1],v);
}
}
// for(int i=1;i<=n;i++) cout<<dist[i]<<"\n";;
for (int i = 1; i <= n; i++) {
if (dist1[i] % 2 == 0) cout <<min(dist1[i]*a,(dist1[i]/2)*b) <<endl;
else cout << min({dist1[i]*a,dist2[i]*b,(dist1[i]/2)*b+a}) <<endl;
}
return;
}
int32_t main() {
// freopen("hayfeast.in", "r", stdin);
// freopen("hayfeast.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
int t=1;
// cin >> t;
while (t--) solve();
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... |