Submission #36225

#TimeUsernameProblemLanguageResultExecution timeMemory
36225WhipppedCreamPrice List (POI13_cen)C++14
10 / 100
126 ms9380 KiB
#include <bits/stdc++.h> //#ifdef atom #else #endif using namespace std; typedef long long ll; typedef pair<int, int> ii; #define X first #define Y second #define vi vector<int> #define vvi vector< vi > #define vii vector< ii > #define mp make_pair #define pb push_back const int maxn = 1e5+5; int n, m, k, a, b; vector<int> adj[maxn]; int odd[maxn]; int eve[maxn]; int dist[maxn]; int p[maxn]; ll cost(int x) { if(x%2) return a+min(1LL*b*(x/2), 1LL*a*(x-1)); return min(1LL*b*x/2, 1LL*a*x); } int main() { //#ifndef atom //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); //#endif scanf("%d %d %d %d %d", &n, &m, &k, &a, &b); for(int i = 1; i<= n; i++) dist[i] = odd[i] = eve[i] = 1e9; for(int i = 1; i<= m; i++) { int a, b; scanf("%d %d", &a, &b); adj[a].pb(b); adj[b].pb(a); } eve[k] = dist[k] = 0; queue<ii> Q; Q.push(ii(k, 0)); while(!Q.empty()) { int u = Q.front().X; Q.pop(); for(auto v : adj[u]) { if(dist[v]> dist[u]+1) { dist[v] = dist[u]+1; p[v] = u; Q.push(ii(v, 0)); } } } Q.push(ii(k, 0)); while(!Q.empty()) { int u = Q.front().X; int par = Q.front().Y; Q.pop(); for(auto v : adj[u]) { if(p[v] == p[u]) continue; if(par) { if(eve[v]> odd[u]+1) { eve[v] = odd[u]+1; Q.push(ii(v, 0)); } } else { if(odd[v]> eve[u]+1) { odd[v] = eve[u]+1; Q.push(ii(v, 1)); } } } } //for(int i = 1; i<= n; i++) printf("%d %d [%d] {%d}\n", odd[i], eve[i], dist[i], p[i]); for(int i = 1; i<= n; i++) { if(odd[i] != 1) printf("%lld\n", min(cost(odd[i]), cost(eve[i]))); else printf("%lld\n", cost(odd[i])); } }

Compilation message (stderr)

cen.cpp: In function 'int main()':
cen.cpp:31:48: 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:35:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int a, b; scanf("%d %d", &a, &b);
                                         ^
#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...