답안 #952993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952993 2024-03-25T09:25:21 Z LucaIlie Designated Cities (JOI19_designated_cities) C++17
9 / 100
363 ms 39412 KB
#include <bits/stdc++.h>

using namespace std;

struct edge {
    int u, v, c, d;

    int other( int p ) {
        return u ^ v ^ p;
    }

    int cost( int p ) {
        if ( p == u )
            return d;
        return c;
    }
};

const int MAX_N = 2e5;
int parent[MAX_N + 1];
long long cost[MAX_N + 1], parentEdgeCost[MAX_N + 1];
long long sumCost;
edge edges[MAX_N];
vector<int> adj[MAX_N + 1];

void dfs( int u, int p ) {
    for ( int e: adj[u] ) {
        int v = edges[e].other( u ), c = edges[e].cost( u ), d = (edges[e].c ^ edges[e].d ^ c);
        if ( v == p )
            continue;

        parent[v] = u;
        cost[v] = cost[u] + d;
        sumCost += c;

        dfs( v, u );
    }
}

int main() {
    int n;
    long long sumTotal = 0;

    cin >> n;
    for ( int i = 0; i < n - 1; i++ ) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        edges[i] = { u, v, c, d };
        adj[u].push_back( i );
        adj[v].push_back( i );
        sumTotal += c + d;
    }

    int q, e;
    cin >> q >> e;

    sumCost = 0;
    dfs( 1, 0 );

    int r = 1;
    for ( int v = 2; v <= n; v++ ) {
        if ( cost[v] > cost[r] )
            r = v;
    }

    sumCost = 0;
    cost[r] = 0;
    dfs( r, 0 );

    long long maxx = 0;
    for ( int v = 1; v <= n; v++ ) {
        if ( cost[v] > maxx )
            maxx = cost[v];
    }

    cout << sumTotal - (sumCost + maxx);

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 353 ms 17748 KB Output is correct
3 Correct 350 ms 39412 KB Output is correct
4 Correct 280 ms 22608 KB Output is correct
5 Correct 298 ms 23840 KB Output is correct
6 Correct 363 ms 26340 KB Output is correct
7 Correct 257 ms 24380 KB Output is correct
8 Correct 348 ms 33560 KB Output is correct
9 Correct 239 ms 24264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -