답안 #928175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928175 2024-02-16T02:49:27 Z Darren0724 Designated Cities (JOI19_designated_cities) C++17
0 / 100
173 ms 23288 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e18;
int n;
vector<pair<int,int>> adj[N];
vector<int> v(N);
void dfs1(int k,int pa){
    for(auto [j,c]:adj[k]){
        if(j==pa)continue;
        v[1]+=c;
        dfs1(j,k);
    }
} 
void dfs2(int k,int pa,int now){
    for(auto [j,c]:adj[k]){
        if(j==pa){
            v[k]=now+c;
            continue;
        }
        dfs2(j,k,v[k]-c);
    }
}
int32_t main() {
    LCBorz;
    int n;cin>>n;
    int total=0;
    for(int i=1;i<n;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;
        adj[a].push_back({b,d});
        adj[b].push_back({a,c});
        total+=c+d;
    }
    dfs1(1,1);
    dfs2(1,1,v[1]);
    int mx=*max_element(all(v));
    cout<<total-mx<<endl;
    

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 173 ms 23288 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 173 ms 23288 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -