제출 #102627

#제출 시각아이디문제언어결과실행 시간메모리
102627someone_aa새로운 문제 (POI13_cen)C++17
100 / 100
471 ms28640 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int maxn = 100100; ll n, m, k, a, b; ll dista[maxn], distb[maxn]; vector<int>g[maxn]; set<int>edge[maxn]; vector<int>unsolved[maxn]; bool visiteda[maxn], visitedb[maxn]; void bfs() { for(int i=1;i<=n;i++) dista[i] = 1e9; queue<int>q; visiteda[k] = true; dista[k] = 0; q.push(k); while(!q.empty()) { int curr = q.front(); q.pop(); for(int i:g[curr]) { if(!visiteda[i]) { visiteda[i] = true; dista[i] = dista[curr] + 1; q.push(i); } } } } void bfsb() { for(int i=1;i<=n;i++) { distb[i] = 1e9; } queue<int>q; visitedb[k] = true; distb[k] = 0; q.push(k); while(!q.empty()) { int curr = q.front(); q.pop(); for(int i:g[curr]) { vector<int>temp; for(int j:unsolved[i]) { if(visitedb[j]) continue; temp.pb(j); if(edge[j].find(curr) != edge[j].end()) { continue; } visitedb[j] = true; distb[j] = distb[curr] + 1; q.push(j); } unsolved[i] = temp; } } } int main() { cin>>n>>m>>k>>a>>b; int x, y; for(int i=0;i<m;i++) { cin>>x>>y; g[x].pb(y); g[y].pb(x); edge[x].insert(y); edge[y].insert(x); unsolved[x].pb(y); unsolved[y].pb(x); } bfs(); bfsb(); for(int i=1;i<=n;i++) { if(dista[i] % 2 == 0) { cout<<min(dista[i]*a, (dista[i]/2)*b)<<"\n"; } else { ll cb = INT_MAX; if(visitedb[i]) cb = distb[i] * b; cout<<min(min(dista[i] * a, ((dista[i]-1)/2*b)+a),cb)<<"\n"; } } }
#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...