Submission #1010211

# Submission time Handle Problem Language Result Execution time Memory
1010211 2024-06-28T13:19:31 Z thinknoexit Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 24660 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
bool vis[200200];
vector<pair<int, int>> adj[200200];
ll dx[200200], dy[200200];
void dfs(int v, int p, ll dis[]) {
    for (auto& [x, w] : adj[v]) {
        if (x == p) continue;
        dis[x] = dis[v] + w;
        dfs(x, v, dis);
    }
}
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    for (int i = 0;i < n - 1;i++) {
        adj[U[i]].push_back({ V[i], W[i] });
        adj[V[i]].push_back({ U[i], W[i] });
    }
    dx[X] = dy[Y] = 0;
    dfs(X, -1, dx);
    dfs(Y, -1, dy);
    pq.push({ 0, X }), vis[X] = 1;
    pq.push({ 0, Y }), vis[Y] = 1;
    int cnt = 0;
    while (!pq.empty()) {
        auto x = pq.top();
        int v = pq.top().second;
        ll w = pq.top().first;
        if (K - w < 0) break;
        K -= w;
        cnt++;
        for (auto& [x, w] : adj[v]) {
            if (vis[x]) continue;
            vis[x] = 1;
            pq.push({ min(dx[x], dy[x]), x });
        }
    }
    for (int i = 0;i < n;i++) adj[i].clear(), vis[i] = 0;
    return cnt;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, ll, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:30:14: warning: variable 'x' set but not used [-Wunused-but-set-variable]
   30 |         auto x = pq.top();
      |              ^
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 24660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 8028 KB Time limit exceeded
2 Halted 0 ms 0 KB -