Submission #839896

#TimeUsernameProblemLanguageResultExecution timeMemory
839896mohammad_kilaniClosing Time (IOI23_closing)C++17
8 / 100
99 ms33320 KiB
#include "closing.h" #include <vector> #include <bits/stdc++.h> using namespace std; int n , x , y; long long k; const int N = 200010; vector< pair< int , int > > g[N]; long long a[N] , b[N]; void DFS(int node,int prnt,long long *a,long long dist){ a[node] = dist; for(int i = 0 ;i < (int)g[node].size();i++){ if(g[node][i].first != prnt) DFS(g[node][i].first , node , a , dist + g[node][i].second); } } int max_score(int N, int X, int Y, long long K,std::vector<int> U, std::vector<int> V, std::vector<int> W) { for(int i = 0;i < n;i++) g[i].clear(); n = N, x = X , y = Y , k = K; for(int i = 0 ;i < (int)U.size();i++){ g[U[i]].push_back(make_pair(V[i] , W[i])); g[V[i]].push_back(make_pair(U[i] , W[i])); } DFS(X , -1 , a , 0); DFS(Y, - 1, b , 0); priority_queue < long long > q; for(int i = 0 ;i < n;i++){ q.push(-min(a[i] , b[i])); } int ans = 0; while(!q.empty()){ k += q.top(); q.pop(); if(k < 0) break; ans++; } return ans; }
#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...