답안 #384803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384803 2021-04-02T10:02:17 Z kostia244 Designated Cities (JOI19_designated_cities) C++17
0 / 100
96 ms 23684 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5 + 12;
int n, cst[maxn];
ll edgesum = 0;
vector<array<int, 2>> g[maxn];

ll sub[maxn];
void sub_cost(int v, int p) {
    for(auto [i, id] : g[v]) if(i != p) {
        sub_cost(i, v);
        sub[v] += sub[i] + cst[id];
    }
}
ll arb[maxn];
void reroot_cost(int v, int p, ll sum) {
    arb[v] = sum;
    for(auto [i, id] : g[v]) if(i!=p) {
        reroot_cost(i, v, sum-cst[id]+cst[id^1]);
    }
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int f, t, x, y, i = 1; i < n; i++) {
        cin >> f >> t >> cst[2*i-1] >> cst[2*i-2];
        edgesum += cst[2*i-1];
        edgesum += cst[2*i-2];
        g[f].push_back({t, 2*i-2});
        g[t].push_back({f, 2*i-1});
    }
    sub_cost(1, 0);
    reroot_cost(1, 0, sub[1]);
    int q;
    cin >> q;
    for(int t; q--;) {
        cin >> t;
        if(t == 1) {
            cout << edgesum-*max_element(arb+1, arb+n+1) << '\n';
        }
    }
}

Compilation message

designated_cities.cpp: In function 'int main()':
designated_cities.cpp:26:19: warning: unused variable 'x' [-Wunused-variable]
   26 |     for(int f, t, x, y, i = 1; i < n; i++) {
      |                   ^
designated_cities.cpp:26:22: warning: unused variable 'y' [-Wunused-variable]
   26 |     for(int f, t, x, y, i = 1; i < n; i++) {
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Runtime error 96 ms 23684 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Runtime error 96 ms 23684 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5100 KB Output isn't correct
2 Halted 0 ms 0 KB -