제출 #244415

#제출 시각아이디문제언어결과실행 시간메모리
244415arnold518새로운 문제 (POI13_cen)C++14
30 / 100
332 ms65540 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]; int ans[MAXN/2+10]; struct Queue { int v; ll w; int 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}); PQ.push({it, B, 1}); } while(!PQ.empty()) { Queue now=PQ.top(); PQ.pop(); if(dist[now.v][now.p]<=now.w) continue; dist[now.v][now.p]=now.w; if(now.p==1) { for(auto nxt : adj[E[now.v].second]) { if(f(E[now.v].first, E[nxt].second)) continue; PQ.push({nxt, now.w+B, 0}); } } else { for(auto nxt : adj[E[now.v].second]) { PQ.push({nxt, now.w+2*A, 0}); PQ.push({nxt, now.w+B, 1}); } } } 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); }

컴파일 시 표준 에러 (stderr) 메시지

cen.cpp: In function 'int main()':
cen.cpp:78: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:28:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
cen.cpp:30: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:34: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...