답안 #206071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
206071 2020-03-02T07:17:35 Z PeppaPig Designated Cities (JOI19_designated_cities) C++14
7 / 100
531 ms 48776 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, int> pii;
 
int N, Q;
vector<pii> G[202020], RG[202020];
int deg[202020];
bool chk[202020];
LL ans[202020], sum;
 
priority_queue<pii> PQ;
 
LL d(int u, int p){
    LL ret = 0;
    for (pii v : RG[u]) if (v.second != p) ret += d(v.second, u) + v.first;
    return ret;
}
 
void f(int u, int p){
    ans[1] = min(ans[1], sum);
    for (int i=0; i<(int)G[u].size(); i++){
        if (G[u][i].second == p) continue;
        sum -= RG[u][i].first;
        sum += G[u][i].first;
        f(G[u][i].second, u);
        sum += RG[u][i].first;
        sum -= G[u][i].first;
    }
}
 
int main(){
    int u, v;
    LL x, y;
    scanf("%d", &N);
    for (int i=1; i<N; i++){
        scanf("%d %d %lld %lld", &u, &v, &x, &y);
        G[u].push_back(pii(y, v));
        G[v].push_back(pii(x, u));
        RG[v].push_back(pii(y, u));
        RG[u].push_back(pii(x, v));
        deg[u]++, deg[v]++;
    }
    for (int i=1; i<=N; i++) if (deg[i] == 1) PQ.push(pii(-G[i][0].first, i));
    ans[1] = 1234567890123456ll;
    sum = d(1, 0);
    f(1, 0);
    scanf("%d", &Q);
    while (Q--){
        scanf("%d", &u);
        printf("%lld\n", ans[u]);
    }
    return 0;
}

Compilation message

designated_cities.cpp: In function 'int main()':
designated_cities.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
designated_cities.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %lld %lld", &u, &v, &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
designated_cities.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q);
     ~~~~~^~~~~~~~~~
designated_cities.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &u);
         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9848 KB Output is correct
2 Incorrect 11 ms 9848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 457 ms 39528 KB Output is correct
3 Correct 519 ms 48160 KB Output is correct
4 Correct 445 ms 38248 KB Output is correct
5 Correct 439 ms 39712 KB Output is correct
6 Correct 466 ms 40676 KB Output is correct
7 Correct 371 ms 39380 KB Output is correct
8 Correct 531 ms 48776 KB Output is correct
9 Correct 304 ms 42040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Incorrect 453 ms 33132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9848 KB Output is correct
2 Incorrect 11 ms 9848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Correct 457 ms 39528 KB Output is correct
3 Correct 519 ms 48160 KB Output is correct
4 Correct 445 ms 38248 KB Output is correct
5 Correct 439 ms 39712 KB Output is correct
6 Correct 466 ms 40676 KB Output is correct
7 Correct 371 ms 39380 KB Output is correct
8 Correct 531 ms 48776 KB Output is correct
9 Correct 304 ms 42040 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Incorrect 453 ms 33132 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9848 KB Output is correct
2 Incorrect 11 ms 9848 KB Output isn't correct
3 Halted 0 ms 0 KB -