Submission #1064514

#TimeUsernameProblemLanguageResultExecution timeMemory
1064514EkinOnalPrice List (POI13_cen)C++17
90 / 100
1766 ms17352 KiB
//#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> adj(n+1); for(int i=0;i<m;i++){ int x,y; cin>>x>>y; adj[x].pb(y); adj[y].pb(x); } vi used(n+5),dist(n+5,INF); dist[k]=0; queue<int> q; q.push(k); while(q.size()){ auto node = q.front(); q.pop(); used[node]=true; for(auto u : adj[node]){ if(used[u]) continue; if(dist[u]>dist[node]+1) {q.push(u); dist[u]=dist[node]+1;} } } for(int i=1;i<=n;i++) sort(adj[i].begin(),adj[i].end()); vector<vi> adj2=adj; vi dist1(n+5,INF),vis(n+5); dist1[k]=0; vis[k]=true; q.push(k); while(q.size()){ int node = q.front(); q.pop(); // if(dist[node.s]!=node.f) continue; for(auto nxt1 : adj[node]){ for(auto nxt2 : adj2[nxt1]){ if(vis[nxt2]) continue; if (binary_search(adj[node].begin(), adj[node].end(), nxt2)) continue; dist1[nxt2]=dist1[node]+1; vis[nxt2]=true; q.push(nxt2); } /* vi v; for(auto nxt2:adj2[nxt1]){ if(vis[nxt2]==false) v.pb(nxt2); swap(adj2[nxt1],v); } */ } } // for(int i=1;i<=n;i++) cout<<dist[i]<<"\n";; for(int i=1;i<=n;i++){ if(dist[i]%2) cout<<min({dist[i]*a,(dist[i]/2)*b+a,dist1[i]*b})<<endl; else cout<<min(dist[i]*a,(dist[i]/2)*b)<<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 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...