# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36247 | Flumen | Price List (POI13_cen) | C++11 | 99 ms | 8604 KiB |
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;
vector<int>node[100100];
int ans[100100],mark[100100];
queue<pair<int,int> >Q;
void bfs1(int k,int a,int b){
Q.push(make_pair(k,0));
while(!Q.empty()){
mark[Q.front().first]=1;
ans[Q.front().first]=min(b,2*a)*(Q.front().second/2)+a*(Q.front().second%2);
for(int i=0;i<node[Q.front().first].size();i++){
if(mark[node[Q.front().first][i]]==1)continue;
mark[node[Q.front().first][i]]=1;
Q.push(make_pair(node[Q.front().first][i],Q.front().second+1));
}
Q.pop();
}
}
void bfs2(int k,int a,int b){
int x,y,z;
Q.push(make_pair(k,0));
while(!Q.empty()){
x=Q.front().first;
y=Q.front().second;
Q.pop();
mark[x]=2;
ans[x]=min(ans[x],min(y*b,y*2*a));
for(int i=0;i<node[x].size();i++){
for(int j=0;j<node[node[x][i]].size();j++){
if(mark[node[node[x][i]][j]]==2)continue;
z=lower_bound(node[node[node[x][i]][j]].begin(),node[node[node[x][i]][j]].end(),x)-node[node[node[x][i]][j]].begin();
if(z<node[node[node[x][i]][j]].size()&&node[node[node[x][i]][j]][z]==x)continue;
mark[node[node[x][i]][j]]=2;
Q.push(make_pair(node[node[x][i]][j],y+1));
}
}
}
}
int main(){
int n,m,k,a,b,i,x,y;
scanf("%d%d%d%d%d",&n,&m,&k,&a,&b);
for(i=0;i<m;i++)
{
scanf("%d%d",&x,&y);
node[x].push_back(y);
node[y].push_back(x);
}
for(i=1;i<=n;i++){
sort(node[i].begin(),node[i].end());
}
bfs1(k,a,b);
//bfs2(k,a,b);
for(i=1;i<=n;i++)printf("%d\n",ans[i]);
return 0;
}
Compilation message (stderr)
# | 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... |