Submission #244419

#TimeUsernameProblemLanguageResultExecution timeMemory
244419arnold518Price List (POI13_cen)C++14
0 / 100
4067 ms15992 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; const int INF = 2e9; int N, M, K, A, B; pii E[MAXN+10]; vector<int> adj[MAXN/2+10], adj2[MAXN/2+10]; int dist[MAXN+10][2]; bool vis[MAXN+10][2]; int ans[MAXN/2+10]; struct Queue { int v, w, p; bool operator < (const Queue &p) const { return w>p.w; } }; bool f(int u, int v) { return binary_search(adj2[u].begin(), adj2[u].end(), v); } int main() { int i, j; scanf("%d%d%d%d%d", &N, &M, &K, &A, &B); for(i=1; i<=M; i++) { int u, v; scanf("%d%d", &u, &v); E[i*2-1]={u, v}; E[i*2]={v, u}; adj[u].push_back(i*2-1); adj[v].push_back(i*2); adj2[u].push_back(v); adj2[v].push_back(u); } for(i=1; i<=N; i++) sort(adj2[i].begin(), adj2[i].end()); for(i=1; i<=2*M; i++) dist[i][0]=dist[i][1]=INF; priority_queue<Queue> PQ; for(auto it : adj[K]) { PQ.push({it, 2*A, 0}); dist[it][0]=2*A; vis[it][0]=true; PQ.push({it, B, 1}); dist[it][1]=B; vis[it][1]=true; } while(!PQ.empty()) { Queue now=PQ.top(); PQ.pop(); if(now.p==1) { for(auto nxt : adj[E[now.v].second]) { if(f(E[now.v].first, E[nxt].second)) continue; if(dist[nxt][0]>now.w+B && !vis[nxt][0]) PQ.push({nxt, now.w+B, 0}), dist[nxt][0]=now.w+B, vis[nxt][0]=true; } } else { for(auto nxt : adj[E[now.v].second]) { if(dist[nxt][0]>now.w+2*A && !vis[nxt][0]) PQ.push({nxt, now.w+2*A, 0}), dist[nxt][0]=now.w+2*A, vis[nxt][0]=true; if(dist[nxt][1]>now.w+B && !vis[nxt][1]) PQ.push({nxt, now.w+B, 1}), dist[nxt][1]=now.w+B, vis[nxt][1]=true; } } } for(i=1; i<=N; i++) if(i!=K) ans[i]=INF; for(i=1; i<=2*M; i++) ans[E[i].second]=min(ans[E[i].second], dist[i][0]); for(i=1; i<=N; i++) printf("%lld\n", ans[i]/2); }

Compilation message (stderr)

cen.cpp: In function 'int main()':
cen.cpp:77:47: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
  for(i=1; i<=N; i++) printf("%lld\n", ans[i]/2);
                                       ~~~~~~~~^
cen.cpp:29:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
cen.cpp:31:7: 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:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~
#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...