# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844666 | oneloveforever | Closing Time (IOI23_closing) | C++17 | 84 ms | 20584 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ii pair<int,int>
int n,a,b,k;
vector<vector<ii> >edge;
int Sub1()
{
queue<int>q;
vector<vector<int> >dist(2,vector<int>(n+1,-1));
vector<int>source(2);
source[0]=a;
source[1]=b;
for(int i=0;i<=1;i++)
{
queue<int>q;
q.push(source[i]);
dist[i][source[i]]=0;
while(!q.empty())
{
int x=q.front();
q.pop();
for(ii need:edge[x])
{
int node=need.x;
int value=need.y;
if(dist[i][node]==-1)
{
dist[i][node]=dist[i][x]+value;
q.push(node);
}
}
}
}
if(dist[0][source[1]]<2*k)return -1;
priority_queue<int,vector<int>,greater<int> >p;
for(int i=1;i<=n;i++)
{
if(dist[0][i]<=k)p.push(dist[0][i]);
if(dist[1][i]<=k)p.push(dist[1][i]);
}
int res=k;
int ans=0;
while(!p.empty())
{
int x=p.top();
p.pop();
if(res<x)break;
res-=x;
ans++;
}
return ans;
}
int max_score(int N,int X,int Y,long long K,vector<int>U,vector<int>V,vector<int>W)
{
n=N;
a=X+1;
b=Y+1;
k=K;
edge.resize(n+1);
for(int i=1;i<=N-1;i++)
{
int x=U[i-1]+1;
int y=V[i-1]+1;
int value=W[i-1];
edge[x].push_back({y,value});
edge[y].push_back({x,value});
}
int value=Sub1();
if(value!=-1)return value;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |