답안 #604964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604964 2022-07-25T11:21:05 Z jhnah917 Designated Cities (JOI19_designated_cities) C++14
7 / 100
195 ms 33932 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll N, Q, Sum, CostTo1, C[202020];
vector<pair<ll,ll>> G[202020];

void TreeDP(int v, int b=-1, ll up=0, ll dw=0){
    for(auto [i,w] : G[v]) if(i == b) CostTo1 += w, up += w;
    C[v] = dw - up;
    for(auto [i,w] : G[v]) if(i != b) TreeDP(i, v, up, dw+w);
}

ll CostToRoot(int root){
    return CostTo1 + C[root];
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N;
    for(int i=1; i<N; i++){
        int a, b, c, d; cin >> a >> b >> c >> d; Sum += c + d;
        G[a].emplace_back(b, c); G[b].emplace_back(a, d);
    }
    TreeDP(1);
    cin >> Q;
    ll mx = 0;
    for(int i=1; i<=N; i++) mx = max(mx, CostToRoot(i));
    for(int i=1; i<=Q; i++){
        int t; cin >> t;
        cout << Sum - mx << "\n";
    }
}

Compilation message

designated_cities.cpp: In function 'void TreeDP(int, int, ll, ll)':
designated_cities.cpp:9:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
    9 |     for(auto [i,w] : G[v]) if(i == b) CostTo1 += w, up += w;
      |              ^
designated_cities.cpp:11:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   11 |     for(auto [i,w] : G[v]) if(i != b) TreeDP(i, v, up, dw+w);
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5064 KB Output is correct
2 Correct 194 ms 23088 KB Output is correct
3 Correct 185 ms 33524 KB Output is correct
4 Correct 164 ms 21832 KB Output is correct
5 Correct 168 ms 23104 KB Output is correct
6 Correct 164 ms 24828 KB Output is correct
7 Correct 133 ms 22704 KB Output is correct
8 Correct 195 ms 33932 KB Output is correct
9 Correct 110 ms 22488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5064 KB Output is correct
2 Correct 194 ms 23088 KB Output is correct
3 Correct 185 ms 33524 KB Output is correct
4 Correct 164 ms 21832 KB Output is correct
5 Correct 168 ms 23104 KB Output is correct
6 Correct 164 ms 24828 KB Output is correct
7 Correct 133 ms 22704 KB Output is correct
8 Correct 195 ms 33932 KB Output is correct
9 Correct 110 ms 22488 KB Output is correct
10 Incorrect 2 ms 5076 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5068 KB Output isn't correct
2 Halted 0 ms 0 KB -