이 제출은 이전 버전의 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 ll INF = 1e18;
int N, M, K, A, B;
pii E[MAXN+10];
vector<int> adj[MAXN+10], adj2[MAXN+10];
ll dist[MAXN+10][2];
ll ans[MAXN+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});
if(f(E[now.v].first, E[nxt].second)) continue;
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: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 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... |