답안 #863828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863828 2023-10-21T08:08:19 Z browntoad Designated Cities (JOI19_designated_cities) C++14
7 / 100
173 ms 35100 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pb push_back
#define pii pair<int, int>
#define pip pair<int, pii>
#define f first
#define s second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define endl '\n'

const ll maxn = 3e5+5;
const ll inf = (1ll<<60);
const ll mod = 1e9+7;

int n;
vector<pip> g[maxn];
int cnt = 0, ans = inf;
void dfs(int x, int prev){
    for (auto v:g[x]){
        if (v.f == prev) continue;
        cnt += v.s.f;
        dfs(v.f, x);
    }
}
void dfs2(int x, int prev){
    ans = min(ans, cnt);
    for (auto v:g[x]){
        if (v.f == prev) continue;
        cnt += v.s.s;
        dfs2(v.f, x);
        cnt -= v.s.s;
    }
}
signed main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>n;
    REP(i, n-1){
        int u, v, c, d; cin>>u>>v>>c>>d;
        g[u].pb({v, {c, d-c}});
        g[v].pb({u, {d, c-d}});
    }
    dfs(1, -1); dfs2(1, -1);
    int q; cin>>q;
    cin>>q;
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 7500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 127 ms 26860 KB Output is correct
3 Correct 173 ms 35100 KB Output is correct
4 Correct 142 ms 25424 KB Output is correct
5 Correct 121 ms 26668 KB Output is correct
6 Correct 121 ms 28216 KB Output is correct
7 Correct 121 ms 26104 KB Output is correct
8 Correct 148 ms 35004 KB Output is correct
9 Correct 82 ms 25076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 7500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 127 ms 26860 KB Output is correct
3 Correct 173 ms 35100 KB Output is correct
4 Correct 142 ms 25424 KB Output is correct
5 Correct 121 ms 26668 KB Output is correct
6 Correct 121 ms 28216 KB Output is correct
7 Correct 121 ms 26104 KB Output is correct
8 Correct 148 ms 35004 KB Output is correct
9 Correct 82 ms 25076 KB Output is correct
10 Incorrect 2 ms 7260 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 7500 KB Output isn't correct
2 Halted 0 ms 0 KB -