Submission #209408

# Submission time Handle Problem Language Result Execution time Memory
209408 2020-03-14T06:44:34 Z PeppaPig Price List (POI13_cen) C++14
100 / 100
254 ms 28584 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n, m, k, A, B;
int dp1[N], dp2[N], chk[N];
vector<int> g[N], adj[N];
set<int> S[N];

void bfs_a() {
    fill_n(dp1, N, 2e9), memset(chk, 0, sizeof chk);

    queue<int> Q;
    Q.emplace(k), dp1[k] = 0, chk[k] = 1;
    while(!Q.empty()) {
        int u = Q.front(); Q.pop();
        for(int v : g[u]) if(!chk[v]) {
            dp1[v] = dp1[u] + 1, chk[v] = 1;
            Q.emplace(v);
        }
    }
}

void bfs_b() {
    fill_n(dp2, N, 2e9), memset(chk, 0, sizeof chk);

    queue<int> Q;
    for(int i = 1; i <= n; i++) adj[i] = g[i];
    Q.emplace(k), dp2[k] = 0, chk[k] = 1;
    while(!Q.empty()) {
        int u = Q.front(); Q.pop();
        for(int v : g[u]) {
            vector<int> vec;
            for(int w : adj[v]) if(!chk[w]) {
                vec.emplace_back(w);
                if(S[u].find(w) != S[u].end()) continue;
                chk[w] = 1, dp2[w] = dp2[u] + 1;
                Q.emplace(w);
            }
            swap(vec, adj[v]);
        }
    }
}

int main() {

    scanf("%d %d %d %d %d", &n, &m, &k, &A, &B);
    for(int i = 1, a, b; i <= m; i++) {
        scanf("%d %d", &a, &b);
        g[a].emplace_back(b), g[b].emplace_back(a);
        S[a].emplace(b), S[b].emplace(a);
    }
    bfs_a(), bfs_b(); 
    for(int i = 1; i <= n; i++) {
        int now = dp1[i] / 2 * min(2 * A, B) + dp1[i] % 2 * A;
        if(dp2[i] != 2e9) now = min(now, dp2[i] * B);
        printf("%d\n", now);
    }

    return 0;
}

Compilation message

cen.cpp: In function 'int main()':
cen.cpp:49:10: 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:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 10872 KB Output is correct
2 Correct 10 ms 10872 KB Output is correct
3 Correct 10 ms 10872 KB Output is correct
4 Correct 11 ms 10872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 10872 KB Output is correct
2 Correct 11 ms 10872 KB Output is correct
3 Correct 11 ms 10876 KB Output is correct
4 Correct 12 ms 10872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 11000 KB Output is correct
2 Correct 11 ms 11000 KB Output is correct
3 Correct 12 ms 11000 KB Output is correct
4 Correct 12 ms 11000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 12920 KB Output is correct
2 Correct 23 ms 12920 KB Output is correct
3 Correct 29 ms 13464 KB Output is correct
4 Correct 29 ms 13560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 17912 KB Output is correct
2 Correct 69 ms 18040 KB Output is correct
3 Correct 68 ms 17144 KB Output is correct
4 Correct 107 ms 19576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 23160 KB Output is correct
2 Correct 111 ms 21496 KB Output is correct
3 Correct 201 ms 25336 KB Output is correct
4 Correct 214 ms 25976 KB Output is correct
5 Correct 133 ms 24180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 25592 KB Output is correct
2 Correct 114 ms 21884 KB Output is correct
3 Correct 220 ms 26360 KB Output is correct
4 Correct 214 ms 25980 KB Output is correct
5 Correct 155 ms 25804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 187 ms 28024 KB Output is correct
2 Correct 180 ms 26232 KB Output is correct
3 Correct 234 ms 27000 KB Output is correct
4 Correct 214 ms 25976 KB Output is correct
5 Correct 176 ms 27380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 26932 KB Output is correct
2 Correct 183 ms 26872 KB Output is correct
3 Correct 235 ms 27384 KB Output is correct
4 Correct 215 ms 26104 KB Output is correct
5 Correct 193 ms 28532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 28408 KB Output is correct
2 Correct 186 ms 28280 KB Output is correct
3 Correct 254 ms 28280 KB Output is correct
4 Correct 211 ms 26104 KB Output is correct
5 Correct 190 ms 28584 KB Output is correct