# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
244416 | arnold518 | 새로운 문제 (POI13_cen) | C++14 | 4100 ms | 19236 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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}); dist[it][0]=2*A;
PQ.push({it, B, 1}); dist[it][1]=B;
}
while(!PQ.empty())
{
Queue now=PQ.top(); PQ.pop();
if(dist[now.v][now.p]!=now.w) continue;
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) PQ.push({nxt, now.w+B, 0}), dist[nxt][0]=now.w+B;
}
}
else
{
for(auto nxt : adj[E[now.v].second])
{
if(dist[nxt][0]>now.w+2*A) PQ.push({nxt, now.w+2*A, 0}), dist[nxt][0]=now.w+2*A;
if(dist[nxt][1]>now.w+B) PQ.push({nxt, now.w+B, 1}), dist[nxt][1]=now.w+B;
}
}
}
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) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |