Submission #1059649

# Submission time Handle Problem Language Result Execution time Memory
1059649 2024-08-15T06:44:01 Z noyancanturk Closing Time (IOI23_closing) C++17
8 / 100
77 ms 35464 KB
#include "closing.h"

#include<bits/stdc++.h>
using namespace std;

#define pb push_back

const int lim=2e5+100;

using lint=long long;

using pii=pair<lint,lint>;

int n;

vector<pii>v[lim];

vector<lint>ds;

void dfs(int node,int par){
    for(auto[j,c]:v[node]){
        if(j==par)continue;
        ds[j]=ds[node]+c;
        dfs(j,node);
    }
}

vector<lint>getdist(int root){
    ds=vector<lint>(n);
    dfs(root,-1);
    return ds;
}

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++){
        v[i].clear();
    }
    for(int i=0;i<n-1;i++){
        v[U[i]].pb({V[i],W[i]});
        v[V[i]].pb({U[i],W[i]});
    }
    vector<lint>dist1=getdist(X),dist2=getdist(Y);
    if(2*K<dist1[Y]){
        //case 1
        priority_queue<pii,vector<pii>,greater<pii>>pq;
        pq.push({0,X});
        pq.push({0,Y});
        bool vis[n]{};
        int ans=0;
        while(pq.size()){
            auto[c,node]=pq.top();
            pq.pop();
            if(K<c)break;
            vis[node]=1;
            K-=c;
            ans++;
            for(auto[j,d]:v[node]){
                if(vis[j])continue;
                pq.push({c+d,j});
            }
        }
        return ans;
    }else{
        //case 2 3 5 6
        assert(0);
        return -1;
    }
    return -1;
}
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 31412 KB Output is correct
2 Correct 77 ms 35464 KB Output is correct
3 Correct 38 ms 10208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 10076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -