Submission #858240

# Submission time Handle Problem Language Result Execution time Memory
858240 2023-10-07T16:54:09 Z Danilo21 Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 44260 KB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

const ll LINF = 2e18;
const int mxN = 1e6+10, INF = 2e9;
ll n, x, y, k, a[mxN], sum, cnt;
vector<array<ll, 2> > g[mxN];
bool vis[2][mxN];
priority_queue<array<ll, 3>,
        vector<array<ll, 3> >,
        greater<array<ll, 3> > > pq;

void Reset(){

    sum = cnt = 0;
    while (pq.size()) pq.pop();
    for (int i = 0; i < n; i++){
        a[i] = 0;
        vis[0][i] = vis[1][i] = 0;
    }
}

void Add(int s, ll d, int t){

    sum += d;
    a[s] += d;
    vis[t][s] = 1;
    for (auto [u, w] : g[s]){
        if (!vis[t][u]){
            pq.push({max(0LL, a[s] + w - a[u]), u, t});
            vis[t][u] = 1;
        }
    }
}

int BFS(){

    int ans = cnt;
    while (pq.size()){
        auto [d, s, t] = pq.top(); pq.pop();
        if (sum + d > k) break;
        ans++;
        Add(s, d, t);
    }
    Reset();
    return ans;
}

int Solve1(){

    Add(x, 0, 0); Add(y, 0, 1);
    cnt = 2;
    return BFS();
}

ll dist[2][mxN], par[mxN], depth[mxN];

void dfs(int s, int p, ll d, int c, int t){

    dist[t][s] = d;
    par[s] = p;
    depth[s] = c;
    for (auto [u, w] : g[s])
        if (u^p) dfs(u, s, d+w, c+1, t);
}

int Solve2(){

    dfs(y, -1, 0, 0, 1);
    dfs(x, -1, 0, 0, 0);
    vector<int> path;
    int s = y;
    while (~s){
        path.pb(s);
        s = par[s];
    }
    int ans = Solve1();
    for (int u : path){
        for (int v : path){
            if (depth[v] <= depth[u]){
                Add(v, max(0LL, dist[0][v] - a[v]), 0);
                cnt++;
            }
            if (depth[v] >= depth[u]){
                Add(v, max(0LL, dist[1][v] - a[v]), 1);
                cnt++;
            }
        }
        if (sum <= k) smax(ans, BFS());
        else Reset();
    }
    return ans;
}

int Solve(){

    if (n <= 3000) return Solve2();
    return Solve1();
}

int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W){

    n = N; k = K;
    x = X; y = Y;
    for (int i = 0; i < n-1; i++){
        g[U[i]].pb({V[i], W[i]});
        g[V[i]].pb({U[i], W[i]});
    }
    int ans = Solve();
    for (int i = 0; i < n; i++)
        g[i].clear();
    return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 42836 KB Output is correct
2 Correct 79 ms 44260 KB Output is correct
3 Execution timed out 1071 ms 35932 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Incorrect 6 ms 33116 KB 1st lines differ - on the 1st token, expected: '30', found: '25'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Incorrect 6 ms 33116 KB 1st lines differ - on the 1st token, expected: '30', found: '25'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Incorrect 6 ms 33116 KB 1st lines differ - on the 1st token, expected: '30', found: '25'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33112 KB Output is correct
3 Incorrect 6 ms 33116 KB 1st lines differ - on the 1st token, expected: '30', found: '25'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33112 KB Output is correct
3 Incorrect 6 ms 33116 KB 1st lines differ - on the 1st token, expected: '30', found: '25'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33112 KB Output is correct
3 Incorrect 6 ms 33116 KB 1st lines differ - on the 1st token, expected: '30', found: '25'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33112 KB Output is correct
3 Incorrect 6 ms 33116 KB 1st lines differ - on the 1st token, expected: '30', found: '25'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 6 ms 33112 KB Output is correct
3 Incorrect 6 ms 33116 KB 1st lines differ - on the 1st token, expected: '30', found: '25'
4 Halted 0 ms 0 KB -