Submission #1006779

# Submission time Handle Problem Language Result Execution time Memory
1006779 2024-06-24T08:31:23 Z 3as8 Closing Time (IOI23_closing) C++17
8 / 100
79 ms 34364 KB
#include "closing.h"

#include <vector>
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;


#define ll long long
#define pll pair<ll, ll>

ll n;
vector<pair<ll, ll> > graph[N];
ll dist[N][2];

void dfs(ll startIndex, ll ind, ll p = -1, ll dep = 0) {


    dist[startIndex][ind] = dep;
    for(auto [el, w] : graph[startIndex]) {
        if(el == p) continue;

        dfs(el, ind, startIndex, dep + w);
    }

}

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

    n = N;
    for(int i = 0 ; i < n; i++ ) {
        graph[i].clear();
    }

    for(int i = 0; i < n - 1; i++) {
        graph[U[i]].push_back({V[i], W[i]});
        graph[V[i]].push_back({U[i], W[i]});
    }

    dfs(X, 0);
    dfs(Y, 1);

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

        //cout<<i<<" "<<dist[i][0]<<" "<<dist[i][1]<<endl;
    }

    priority_queue<pll, vector<pll>, greater<pll> > pq;
    for(int i = 0; i < n; i++) {
        if(dist[i][0] < dist[i][1]) {
            pq.push({dist[i][0], i});
            dist[i][1] -= dist[i][0];
            dist[i][0] = -1;
        } else {
            pq.push({dist[i][1], i});
            dist[i][0] -= dist[i][1];
            dist[i][1] = -1;
        }
    }

    ll curr = 0;
    ll ans = 0;
    while(!pq.empty()) {

        auto [dista, node] = pq.top();
        pq.pop();

        //cout<<" = > "<<dista<<" "<<node<<endl;

        if(curr + dista <= K) {
            ans += 1;
            curr += dista;

            if(dist[node][0] != -1) {
                pq.push({dist[node][0], node});
                dist[node][0] = -1;
            }
             if(dist[node][1] != -1) {
                pq.push({dist[node][1], node});
                dist[node][1] = -1;
            }
        }  else break;
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5980 KB 2nd lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 31176 KB Output is correct
2 Correct 79 ms 34364 KB Output is correct
3 Correct 42 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Incorrect 2 ms 5980 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Incorrect 2 ms 5980 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Incorrect 2 ms 5980 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5980 KB 2nd lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5980 KB 2nd lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5980 KB 2nd lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5980 KB 2nd lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5980 KB 2nd lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -