# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36209 | WhipppedCream | Price List (POI13_cen) | C++14 | 116 ms | 8600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
int odd[maxn];
int eve[maxn];
int cost(int x)
{
return min(2*a, b)*(x/2)+a*(x%2);
}
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<= n; i++) odd[i] = eve[i] = 1e9;
for(int i = 1; i<= m; i++)
{
int a, b; scanf("%d %d", &a, &b);
adj[a].pb(b); adj[b].pb(a);
}
eve[k] = 0;
queue<ii> Q; Q.push(ii(k, 0));
while(!Q.empty())
{
int u = Q.front().X; int par = Q.front().Y; Q.pop();
for(auto v : adj[u])
{
if(par)
{
if(eve[v]> odd[u]+1)
{
eve[v] = odd[u]+1;
Q.push(ii(v, 0));
}
}
else
{
if(odd[v]> eve[u]+1)
{
odd[v] = eve[u]+1;
Q.push(ii(v, 1));
}
}
}
}
for(int i = 1; i<= n; i++) printf("%d\n", min(cost(odd[i]), cost(eve[i])));
}
Compilation message (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... |