Submission #1060372

#TimeUsernameProblemLanguageResultExecution timeMemory
1060372dozerClosing Time (IOI23_closing)C++17
0 / 100
183 ms23380 KiB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " " 
#define endl "\n"
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define LL node * 2
#define RR node * 2 + 1
#define ll long long

const int modulo = 1e9 + 7;
const ll INF = 2e18 + 7;


int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W)
{
    vector<pii> adj[N + 5];
    vector<ll> dist1(N, -1), dist2(N, -1);
    vector<ll> par1(N, -1), par2(N, -1);

    for (ll i = 0; i < N - 1; i++){
        adj[U[i]].pb({V[i], W[i]});
        adj[V[i]].pb({U[i], W[i]});
    }

    priority_queue<pair<ll, ll>> q;
    q.push({0, X});

    while(!q.empty()){
        pii tmp = q.top();
        q.pop();
        ll top = tmp.nd, d = -tmp.st;
        dist1[top] = d;
        for (auto i : adj[top]){
            ll v = i.st, w = i.nd;
            if (dist1[v] != -1) continue;
            par1[v] = top;
            q.push({-(d + w), v});
        }
    }

     q.push({0, Y});

     ll ans = 0;

    while(!q.empty()){
        pii tmp = q.top();
        q.pop();
        ll top = tmp.nd, d = -tmp.st;
        dist2[top] = d;
        for (auto i : adj[top]){
            ll v = i.st, w = i.nd;
            if (dist2[v] != -1) continue;
            par2[v] = top;
            q.push({-(d + w), v});
        }
    }

    for(ll i = 0; i < (1<<N); i++){
        vector<ll> v;
        ll sum = 0, res = 0;
        for (ll j = 0; j < N; j++){
            if (i & (1<<j)){
                res++;
                if (dist1[j] > dist2[j]) swap(dist1[j], dist2[j]), swap(par1[j], par2[j]);
                if (par1[j] == -1 || (i & (1<<par1[j]))){
                    sum += dist1[j];
                    if (par2[j] == -1 || (i & (1<<par2[j]))){
                        v.pb(dist2[j] - dist1[j]);
                    }
                }
                else if (par2[j] == -1 || (i & (1<<par2[j]))){
                    sum += dist2[j];
                }
                else{
                    res--;
                }
               
            }
        }

        sort(v.begin(), v.end());
        ll it = 0;
        while(it < v.size() && sum + v[it] <= K) {
            sum += v[it], res++;
            it++;
        }
        if (sum <= K) ans = max(ans, res);
    }
    return ans;
}

Compilation message (stderr)

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:89:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         while(it < v.size() && sum + v[it] <= K) {
      |               ~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...