Submission #376203

# Submission time Handle Problem Language Result Execution time Memory
376203 2021-03-11T04:30:22 Z wiwiho Designated Cities (JOI19_designated_cities) C++14
7 / 100
307 ms 32108 KB
#include <bits/stdc++.h>
 
#define eb emplace_back
#define printv(a, b) { \
    for(auto pv : a) b << pv << " "; \
    b << "\n"; \
}
#define mp make_pair
#define F first
#define S second
 
using namespace std;

typedef long long ll;
using pll = pair<ll, ll>;

struct edge{
    int a, b, c, d;
    ll get(int v){
        if(v == b) return c;
        else return d;
    }
    int ano(int v){
        return a ^ b ^ v;
    }
};

vector<vector<edge>> g;
vector<ll> dp, ans;

void dfs(int now, int p){
    //cerr << "dfs " << now << "\n";
    for(edge i : g[now]){
        int v = i.ano(now);
        if(v == p) continue;
        dfs(v, now);
        dp[now] += i.get(v) + dp[v];
    }
}

void dfs2(int now, int p){
    for(edge i : g[now]){
        int v = i.ano(now);
        if(v == p){
            //cerr << "dfs2 " << now << " " << p << " "  << ans[p] << " " << i.get(now) << " " << i.get(p) << "\n";
            ans[now] = ans[p] - i.get(now) + i.get(p);
            continue;
        }
    }
    for(edge i : g[now]){
        int v = i.ano(now);
        if(v != p) dfs2(v, now);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    int n;
    cin >> n;

    
    g.resize(n + 1);
    dp.resize(n + 1);
    ans.resize(n + 1);

    for(int i = 0; i < n - 1; i++){
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        g[u].eb(edge({u, v, c, d}));
        g[v].eb(edge({u, v, c, d}));
    }

    dfs(1, 1);
    ans[1] = dp[1];
    dfs2(1, 1);

    ll mn = 1LL << 60;
    for(int i = 1; i <= n; i++) mn = min(mn, ans[i]);
    //printv(dp, cerr);
    //printv(ans, cerr);

    int q;
    cin >> q;

    while(q--){
        int e;
        cin >> e;
        cout << mn << "\n";
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 260 ms 18668 KB Output is correct
3 Correct 307 ms 31596 KB Output is correct
4 Correct 255 ms 18796 KB Output is correct
5 Correct 250 ms 18588 KB Output is correct
6 Correct 275 ms 20588 KB Output is correct
7 Correct 222 ms 18140 KB Output is correct
8 Correct 292 ms 32108 KB Output is correct
9 Correct 192 ms 17888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 260 ms 18668 KB Output is correct
3 Correct 307 ms 31596 KB Output is correct
4 Correct 255 ms 18796 KB Output is correct
5 Correct 250 ms 18588 KB Output is correct
6 Correct 275 ms 20588 KB Output is correct
7 Correct 222 ms 18140 KB Output is correct
8 Correct 292 ms 32108 KB Output is correct
9 Correct 192 ms 17888 KB Output is correct
10 Incorrect 1 ms 364 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -