Submission #36242

#TimeUsernameProblemLanguageResultExecution timeMemory
36242FlumenPrice List (POI13_cen)C++11
70 / 100
4000 ms8912 KiB
#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)

cen.cpp: In function 'void bfs1(int, int, int)':
cen.cpp:11:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<node[Q.front().first].size();i++){
                      ^
cen.cpp: In function 'void bfs2(int, int, int)':
cen.cpp:28:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<node[x].size();i++){
                      ^
cen.cpp:29:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0;j<node[node[x][i]].size();j++){
                          ^
cen.cpp:32:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(z<node[node[node[x][i]][j]].size()&&node[node[node[x][i]][j]][z]==x)continue;
                     ^
cen.cpp: In function 'int main()':
cen.cpp:41:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d%d",&n,&m,&k,&a,&b);
                                       ^
cen.cpp:44:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...