Submission #1060032

# Submission time Handle Problem Language Result Execution time Memory
1060032 2024-08-15T10:11:30 Z tolbi Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 40528 KB
#include "closing.h"

#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int MAXN = 3023;
long long dp1[MAXN], dp2[MAXN],dp3[MAXN];
int32_t max_score(int32_t N, int32_t X, int32_t Y, long long K,
  std::vector<int32_t> U, std::vector<int32_t> V, std::vector<int32_t> W)
{
    vector<vector<pair<int,int>>> arr(N);
    for (int i = 0; i < N-1; i++){
        arr[U[i]].push_back({V[i],W[i]});
        arr[V[i]].push_back({U[i],W[i]});
    }
    queue<pair<int,int>> q;
    vector<bool> vis(N,false);
    q.push({0,X});
    while (q.size()){
        int node = q.front().second;
        int w = q.front().first;
        q.pop();
        if (vis[node]) continue;
        vis[node]=true;
        dp1[node]=w;
        for (auto it : arr[node]){
            q.push({it.second+w,it.first});
        }
    }
    fill(vis.begin(), vis.end(), false);
    q.push({0,Y});
    while (q.size()){
        int node = q.front().second;
        int w = q.front().first;
        q.pop();
        if (vis[node]) continue;
        vis[node]=true;
        dp2[node]=w;
        for (auto it : arr[node]){
            q.push({it.second+w,it.first});
        }
    }
    for (int i = 0; i < N; i++){
        dp3[i]=max(dp1[i],dp2[i]);
    }
    int ans = 0;
    for (int i = 0; i < (1<<N); i++){
        long long cur = 0;
        priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>> pq;
        fill(vis.begin(), vis.end(), false);
        int cans = 0;
        for (int j = 0; j < N; j++){
            if ((1<<j)&i){
                cans+=2;
                cur+=dp3[j];
                vis[j]=true;
                for (auto it : arr[j]){
                    pq.push({dp1[it.first],it.first,0});
                    pq.push({dp2[it.first],it.first,1});
                }
            }
        }
        if (i==0){
            pq.push({0,X,0});
            pq.push({0,Y,1});
        }
        while (pq.size()){
            int w = pq.top()[0];
            int node = pq.top()[1];
            int flag = pq.top()[2];
            pq.pop();
            if (vis[node]) continue;
            if (cur+w>K) break;
            cur+=w;
            vis[node]=true;
            cans++;
            for (auto it : arr[node]){
                if (flag==0){
                    pq.push({dp1[it.first],it.first,0});
                }
                else {
                    pq.push({dp2[it.first],it.first,1});
                }
            }
        }
        if (cur<=K && vis[X] && vis[Y]) ans=max(ans,cans);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 40528 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1100 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1100 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1100 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1100 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1100 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1100 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1100 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 1100 ms 348 KB Time limit exceeded
4 Halted 0 ms 0 KB -