QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#523439 | #7118. Closing Time | kimmoqt | 0 | 2ms | 7944kb | C++20 | 3.5kb | 2024-08-18 11:00:42 | 2024-08-18 11:00:44 |
answer
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=2e5+5;
int par[MX];
ll A[MX],B[MX];
vector<pair<int,int>> adj[MX];
bool vis[MX], calc[MX];
void dfs(int v, int p) {
par[v]=p;
for(auto [u,w]:adj[v]) {
if(u==p) continue;
A[u]=A[v]+w;
dfs(u,v);
}
}
void dfs2(int v, int p) {
for(auto [u,w]:adj[v]) {
if(u==p) continue;
B[u]=B[v]+w;
dfs2(u,v);
}
}
// called multiple times
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++) {
adj[i].clear();
vis[i]=calc[i]=false;
par[i]=-1;
A[i]=B[i]=0;
}
for(int i=0;i<N-1;i++) {
adj[U[i]].push_back({V[i],W[i]});
adj[V[i]].push_back({U[i],W[i]});
}
dfs(X,-1);
dfs2(Y,-1);
priority_queue<pair<ll,ll>> pq;
int v=Y;
vector<int> path;
while(v!=X) {
path.push_back(v);
v=par[v];
}
path.push_back(X);
v=Y;
while(v!=X) {
if(A[par[v]]<B[par[v]]) {
pq.push({-abs(A[par[v]]-B[par[v]]),par[v]});
pq.push({-abs(A[v]-B[v]),v});
vis[par[v]]=true;
vis[v]=true;
break;
}
v=par[v];
}
int ans=0,cnt=0;
ll sum=0;
vector<ll> vals;
for(int i=0;i<N;i++) vals.push_back(min(A[i],B[i]));
sort(vals.begin(),vals.end());
ll cur=0;
for(int i=0;i<N;i++) {
cur+=vals[i];
if(cur<=K) ans=max(ans,i+1);
}
while(!pq.empty()) {
auto [d,v]=pq.top(); pq.pop();
d=-d;
calc[v]=true;
cnt+=2;
sum+=min(A[v],B[v]);
sum+=d;
ll cur=sum;
vector<int> del;
for(auto x:path) {
if(!calc[x]) {
cur+=min(A[x],B[x]);
del.push_back(x);
calc[x]=true;
cnt++;
}
}
vector<pair<ll,ll>> vals;
for(int i=0;i<N;i++) {
if(!calc[i]) {
vals.push_back({min(A[i],B[i]),i});
}
}
sort(vals.begin(),vals.end());
for(int i=0;i<vals.size();i++) {
if(cur+vals[i].first>K) break;
cur+=vals[i].first;
cnt++;
del.push_back(vals[i].second);
}
if(cur<=K) ans=max(ans,cnt);
for(auto [u,w]:adj[v]) {
if(!vis[u]) {
vis[u]=true;
pq.push({-abs(A[u]-B[u]),u});
}
}
for(auto x:del) {
calc[x]=false;
cnt--;
}
}
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 200000 31011 61157 8517583098 31011 129396 964383 1655 129396 331139 1655 191487 566483 110385 191487 865248 43212 110385 542661 43212 81682 13766 81682 91774 546589 91774 124706 780638 124706 175650 118706 10421 175650 615314 10421 151953 436270 140430 151...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 9
Accepted
time: 2ms
memory: 7944kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 50 23 25 382806473 0 1 375710 1 2 898637 2 3 10402 3 4 536577 4 5 385023 5 6 71075 6 7 543368 7 8 301497 8 9 174394 9 10 711312 10 11 923006 11 12 675532 12 13 838667 13 14 565729 14 15 979816 15 16 862618 16 17 576015 17 18 177751 18 19 306989 19 20 881492...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 96
result:
ok
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 7936kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 47 20 22 25669694 0 1 291237 1 2 851987 2 3 421247 3 4 962919 4 5 643085 5 6 224951 6 7 756890 7 8 147295 8 9 625823 9 10 736374 10 11 290526 11 12 335466 12 13 539086 13 14 957449 14 15 423408 15 16 932444 16 17 356032 17 18 307118 18 19 94279 19 20 989546...
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 24
result:
wrong answer 1st lines differ - on the 1st token, expected: '26', found: '24'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #36:
score: 9
Accepted
time: 2ms
memory: 7940kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 9 0 2 2 1 2 3 2 3 3
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 6
result:
ok
Test #37:
score: 0
Wrong Answer
time: 1ms
memory: 5864kb
input:
cc61ad56a4797fb3f5c9529f73ce6fcedd85669b 1 4 0 1 8 0 2 2 1 2 3 2 3 100
output:
081ce3c351cbf526b37954b9ad30f2b531a7585c OK 4
result:
wrong answer 1st lines differ - on the 1st token, expected: '5', found: '4'
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #4:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
0%