답안 #1108358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108358 2024-11-04T01:16:13 Z Zero_OP Designated Cities (JOI19_designated_cities) C++14
7 / 100
173 ms 38216 KB
#include <bits/stdc++.h>

using namespace std;

#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()

template<typename T>
    bool minimize(T& a, const T& b){
        if(a > b){
            return a = b, true;
        }
        return false;
    }
template<typename T>
    bool maximize(T& a, const T& b){
        if(a < b){
            return a = b, true;
        }
        return false;
    }

using ll = long long;
using ld = long double;
using ull = unsigned long long;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

#ifdef LOCAL
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
#endif // LOCAL

    int N;
    cin >> N;
    vector<vector<tuple<int, int, int>>> adj(N);
    for(int i = 0; i < N - 1; ++i){
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        --u, --v;
        adj[u].emplace_back(v, c, d);
        adj[v].emplace_back(u, d, c);
    }

    vector<ll> f(N), g(N);

    function<void(int, int)> dfs = [&](int u, int p){
        for(auto [v, c, d] : adj[u]) if(v != p){
            dfs(v, u);
            f[u] += f[v] + c;
        }
    };

    dfs(0, -1);
    g[0] = f[0];

    function<void(int, int)> reroot_dfs = [&](int u, int p){
        for(auto [v, c, d] : adj[u]) if(v != p){
            g[v] = g[u] - c + d;
            reroot_dfs(v, u);
        }
    };

    reroot_dfs(0, -1);
    vector<long long> answer(N + 1, LLONG_MAX);

    for(int i = 0; i < N; ++i){
        answer[1] = min(answer[1], g[i]);
    }

    int Q;
    cin >> Q;
    while(Q--){
        int k;
        cin >> k;
        cout << answer[k] << '\n';
    }

    return 0;
}

Compilation message

designated_cities.cpp: In lambda function:
designated_cities.cpp:51:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |         for(auto [v, c, d] : adj[u]) if(v != p){
      |                  ^
designated_cities.cpp: In lambda function:
designated_cities.cpp:61:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |         for(auto [v, c, d] : adj[u]) if(v != p){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 144 ms 24404 KB Output is correct
3 Correct 173 ms 37704 KB Output is correct
4 Correct 101 ms 22856 KB Output is correct
5 Correct 121 ms 24224 KB Output is correct
6 Correct 123 ms 26328 KB Output is correct
7 Correct 103 ms 24208 KB Output is correct
8 Correct 148 ms 38216 KB Output is correct
9 Correct 86 ms 24768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 144 ms 24404 KB Output is correct
3 Correct 173 ms 37704 KB Output is correct
4 Correct 101 ms 22856 KB Output is correct
5 Correct 121 ms 24224 KB Output is correct
6 Correct 123 ms 26328 KB Output is correct
7 Correct 103 ms 24208 KB Output is correct
8 Correct 148 ms 38216 KB Output is correct
9 Correct 86 ms 24768 KB Output is correct
10 Incorrect 1 ms 336 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -