Submission #1060550

# Submission time Handle Problem Language Result Execution time Memory
1060550 2024-08-15T17:09:36 Z n1k Closing Time (IOI23_closing) C++17
43 / 100
81 ms 36664 KB
#include "closing.h"
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W){
    vector<vector<array<int, 2>>> g(N);
    vector c(2, vector<ll>(N));
    vector<int> par(N);

    for(int i=0; i<N-1; i++){
        g[U[i]].push_back({V[i], W[i]});
        g[V[i]].push_back({U[i], W[i]});
    }
    function<void(int, int, vector<ll>&)> dfs = [&](int u, int p, vector<ll> &c){
        par[u] = p;
        for(auto [v, cost]:g[u]){
            if(v==p){
                continue;
            }
            c[v]+=c[u] + cost;
            dfs(v, u, c);
        }
    };

    dfs(X, -1, c[0]);
    dfs(Y, -1, c[1]);

    auto get = [&](ll K){
        int ans = 0;
        vector vis(2, vector<int>(N));
        priority_queue<array<ll, 3>, vector<array<ll, 3>>, greater<array<ll, 3>>> pq;
        // (cost, node, start x or y)
        pq.push({0, X, 0});
        pq.push({0, Y, 1});
        while(pq.size()){
            auto [cost, u, start] = pq.top();
            pq.pop();
            if(vis[start][u]){
                continue;
            }
            vis[start][u]=1;
            if(K<cost){
                break;
            }
            //cerr << u << " " << cost << " " << start << endl;
            ans++;
            K-=cost;
            for(auto [v, _]:g[u]){
                pq.push({c[start][v], v, start});
            }
        }
        return ans;
    };
    auto get2 = [&](ll K){
        int ans = 0;
        vector vis(2, vector<int>(N));
        priority_queue<array<ll, 3>, vector<array<ll, 3>>, greater<array<ll, 3>>> pq;

        for(int u=X; ; u=par[u]){
            if(min(c[0][u], c[1][u])>K){
                return ans;
            }
            ans++;
            if(c[0][u]<c[1][u]){
                K-=c[0][u];
                vis[0][u]=1;
            }else{
                K-=c[1][u];
                vis[1][u]=1;
            }
            if(u==Y) break;
        }

        for(int u=X; ; u=par[u]){
            for(int start=0; start<2; start++){
                for(auto [v, _]:g[u]){
                    if(vis[start^1][v] and c[start^1][v] <= c[start][v]){
                        pq.push({c[start][v] - c[start^1][v], v, start});
                    }else{
                        pq.push({c[start][v], v, start});
                    }
                    if(vis[start^1][v] and c[start^1][u] >= c[start][u]){
                        pq.push({c[start^1][u] - c[start][u], u, start^1});
                    }
                }
            }
            if(u==Y) break;
        }
        while(pq.size()){
            auto [cost, u, start] = pq.top();
            pq.pop();
            if(vis[start][u]){
                continue;
            }
            vis[start][u]=1;
            if(K<cost){
                break;
            }
            ans++;
            K-=cost;
            for(auto [v, _]:g[u]){
                if(vis[start^1][v] and c[start^1][v] <= c[start][v]){
                    pq.push({c[start][v] - c[start^1][v], v, start});
                }else{
                    pq.push({c[start][v], v, start});
                }
                if(vis[start^1][v] and c[start^1][u] >= c[start][u]){
                    pq.push({c[start^1][u] - c[start][u], u, start^1});
                }
            }
        }
        return ans;
    };
    return max(get(K), get2(K));
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 29752 KB Output is correct
2 Correct 81 ms 36664 KB Output is correct
3 Correct 49 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 3 ms 1376 KB Output is correct
29 Correct 3 ms 1196 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 856 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 3 ms 1376 KB Output is correct
30 Correct 3 ms 1196 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 856 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 3 ms 1376 KB Output is correct
30 Correct 3 ms 1196 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 856 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
35 Halted 0 ms 0 KB -