답안 #834800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834800 2023-08-22T19:45:31 Z Ozy Designated Cities (JOI19_designated_cities) C++17
9 / 100
223 ms 51384 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],h_op[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;
    vector<lli> mejores;
    
    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);
        
        mejores.push_back(h_op[h.des]+h.w);
    }
    sort(mejores.begin(), mejores.end());
    reverse(mejores.begin(), mejores.end());

    lli cont = 0;
    a = carga + sub[pos];
    for(auto m : mejores) {
        if (cont == 2) break;
        cont++;
        a += m;
    }

    op = max(a,op);
    if(!mejores.empty()) h_op[pos] = mejores[0];
}
    
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) << "\n";
    
    return 0;  
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5020 KB Output is correct
2 Correct 223 ms 21760 KB Output is correct
3 Correct 198 ms 51384 KB Output is correct
4 Correct 150 ms 26192 KB Output is correct
5 Correct 155 ms 28116 KB Output is correct
6 Correct 179 ms 31144 KB Output is correct
7 Correct 112 ms 28952 KB Output is correct
8 Correct 196 ms 40828 KB Output is correct
9 Correct 111 ms 25672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -