답안 #834564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834564 2023-08-22T15:28:38 Z Ozy Designated Cities (JOI19_designated_cities) C++17
7 / 100
212 ms 39380 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "

#define MAX 200000

struct x {
    lli des;
    lli w;
    lli comp;
};

lli n,a,b,c,d,raiz,op,total,q;
vector<x> hijos[MAX+2];
lli sub[MAX+2];

void pre_dfs(lli pos, lli padre) {
    for(auto h : hijos[pos]) {
        if(h.des == padre) continue;
        pre_dfs(h.des,pos);
        sub[pos] += sub[h.des] + (h.comp-h.w);
    }
}

void busca_raiz(lli pos, lli padre,lli carga) {

    lli a = carga + sub[pos];
    if (a > op){
        op = a;
        raiz = pos;
    }  

    for(auto h : hijos[pos]){
        if(h.des == padre) continue;
        a = carga + sub[pos] - sub[h.des];
        a -= (h.comp-h.w);
        a += h.w;
        busca_raiz(h.des,pos,a);
    }
}

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

    cin >> n;
    rep(i,1,n-1) {
        cin >> a >> b >> c >> d;
        hijos[a].push_back({b,c,c+d});
        hijos[b].push_back({a,d,c+d});
        total += (c+d);
    }

    pre_dfs(1,0);
    busca_raiz(1,0,0);

    cin >> q >> a;
    cout << (total-op);

    return 0;  
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 174 ms 25928 KB Output is correct
3 Correct 210 ms 38756 KB Output is correct
4 Correct 130 ms 24652 KB Output is correct
5 Correct 164 ms 25744 KB Output is correct
6 Correct 187 ms 28020 KB Output is correct
7 Correct 122 ms 24828 KB Output is correct
8 Correct 212 ms 39380 KB Output is correct
9 Correct 90 ms 22520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 174 ms 25928 KB Output is correct
3 Correct 210 ms 38756 KB Output is correct
4 Correct 130 ms 24652 KB Output is correct
5 Correct 164 ms 25744 KB Output is correct
6 Correct 187 ms 28020 KB Output is correct
7 Correct 122 ms 24828 KB Output is correct
8 Correct 212 ms 39380 KB Output is correct
9 Correct 90 ms 22520 KB Output is correct
10 Incorrect 2 ms 5028 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -