제출 #244422

#제출 시각아이디문제언어결과실행 시간메모리
244422arnold518새로운 문제 (POI13_cen)C++14
100 / 100
1955 ms9712 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 ll INF = 1e15; int N, M, K, A, B; pii E[MAXN+10]; vector<int> adj[MAXN/2+10]; ll dist1[MAXN+10], dist2[MAXN+10]; bool vis1[MAXN+10], vis2[MAXN+10]; struct Queue { int v, w, p; }; bool f(int u, int v) { return binary_search(adj[u].begin(), adj[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); adj[u].push_back(v); adj[v].push_back(u); } for(i=1; i<=N; i++) sort(adj[i].begin(), adj[i].end()); for(i=1; i<=N; i++) dist1[i]=dist2[i]=INF; queue<Queue> Q; Q.push({K, 0, 0}); vis1[K]=1; dist1[K]=0; while(!Q.empty()) { Queue now=Q.front(); Q.pop(); for(auto nxt : adj[now.v]) { if(vis1[nxt]) continue; dist1[nxt]=now.w+1; vis1[nxt]=true; Q.push({nxt, now.w+1, 0}); } } Q.push({K, 0, -1}); vis2[K]=1; dist2[K]=0; while(!Q.empty()) { Queue now=Q.front(); Q.pop(); if(now.p==-1) { for(auto nxt : adj[now.v]) { Q.push({nxt, now.w, now.v}); } } else { for(auto nxt : adj[now.v]) { if(vis2[nxt]) continue; if(f(nxt, now.p)) continue; Q.push({nxt, now.w+1, -1}); vis2[nxt]=true; dist2[nxt]=now.w+1; } } } for(i=1; i<=N; i++) { if(dist1[i]%2==0) printf("%lld\n", min(dist1[i]*A, dist1[i]/2*B)); else printf("%lld\n", min({dist1[i]*A, dist1[i]/2*B+A, dist2[i]*B})); } }

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

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