# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
36517 | WhipppedCream | 새로운 문제 (POI13_cen) | C++14 | 329 ms | 28936 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vvi vector< vi >
#define vii vector< ii >
#define mp make_pair
#define pb push_back
const int maxn = 1e5+5;
int n, m, k, a, b;
vector<int> adj[maxn];
set<int> has[maxn];
vector<int> active[maxn];
bool vis[maxn];
int dist[maxn];
int dist2[maxn];
void bfs(int *dist)
{
for(int i = 1; i<= n; i++) dist[i] = 1e9;
dist[k] = 0;
queue<int> Q; Q.push(k);
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(auto v : adj[u])
{
if(dist[v]> dist[u]+1)
{
dist[v] = dist[u]+1;
Q.push(v);
}
}
}
}
void bfs2(int *dist)
{
for(int i = 1; i<= n; i++) dist[i] = 1e9;
queue<int> Q; Q.push(k);
dist[k] = 0; vis[k] = 1;
for(int i = 1; i<= n; i++) active[i] = adj[i];
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(auto v : adj[u])
{
vector<int> temp;
for(auto w : active[v])
{
if(vis[w]) continue;
if(has[u].find(w) != has[u].end()) continue;
vis[w] = 1;
dist[w] = dist[u]+1;
Q.push(w);
temp.pb(w);
}
active[v] = temp;
}
}
}
int main()
{
//#ifndef atom
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
//#endif
scanf("%d %d %d %d %d", &n, &m, &k, &a, &b);
for(int i = 1; i<= m; i++)
{
int a, b; scanf("%d %d", &a, &b);
adj[a].pb(b); adj[b].pb(a);
has[a].insert(b); has[b].insert(a);
}
bfs(dist); bfs2(dist2);
//for(int i = 1; i<= n; i++) printf("%d\n", dist2[i]);
for(int i = 1; i<= n; i++)
{
int x = (dist[i]/2)*min(2*a, b)+(dist[i]%2)*a;
int y = 2e9;
if(dist2[i] != 1e9) y = dist2[i]*b;
printf("%d\n", min(x, y));
}
}
컴파일 시 표준 에러 (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... |