Submission #952990

# Submission time Handle Problem Language Result Execution time Memory
952990 2024-03-25T09:22:02 Z LucaIlie Designated Cities (JOI19_designated_cities) C++17
7 / 100
307 ms 36716 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 ) {
    //printf( "%d\n", u );
    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;

        //printf( "%d %d %d %d\n", u, v, c, d );

        parent[v] = u;
        cost[v] = cost[u] - c + 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 );

    long long maxx = 0;
    for ( int v = 1; v <= n; v++ )
        maxx = max( maxx, cost[v] );

    cout << sumTotal - (sumCost + maxx);

    /*for ( int r = 1; r <= n; r++ ) {
        sumCost = sumTotal;
        dfs( r, 0 );

        for ( int i = 2; i <= n; i++ ) {

        }
    }*/

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8824 KB Output is correct
2 Correct 245 ms 23752 KB Output is correct
3 Correct 307 ms 36632 KB Output is correct
4 Correct 215 ms 22592 KB Output is correct
5 Correct 269 ms 24016 KB Output is correct
6 Correct 251 ms 25432 KB Output is correct
7 Correct 288 ms 24268 KB Output is correct
8 Correct 289 ms 36716 KB Output is correct
9 Correct 216 ms 24520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8824 KB Output is correct
2 Correct 245 ms 23752 KB Output is correct
3 Correct 307 ms 36632 KB Output is correct
4 Correct 215 ms 22592 KB Output is correct
5 Correct 269 ms 24016 KB Output is correct
6 Correct 251 ms 25432 KB Output is correct
7 Correct 288 ms 24268 KB Output is correct
8 Correct 289 ms 36716 KB Output is correct
9 Correct 216 ms 24520 KB Output is correct
10 Incorrect 2 ms 8796 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -