Submission #839931

# Submission time Handle Problem Language Result Execution time Memory
839931 2023-08-30T21:20:47 Z mohammad_kilani Closing Time (IOI23_closing) C++17
8 / 100
121 ms 40360 KB
#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);
    }
}

vector< int > path;

bool DFS(int node,int prnt){
    path.push_back(node);
    if(node == y)
    return true;
    for(int i = 0 ;i < (int)g[node].size();i++){
        if(g[node][i].first == prnt) continue;
        if(DFS(g[node][i].first , node))
        return true;
    }
    path.pop_back();
    return false;
}

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();
    path.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++;
    }
    DFS(X , -1);
    long long cur = 0;

    priority_queue < pair< long long , pair< int , bool > > > q2;
    long long val;
    vector< int > done(n , 0);
    int ans2 = (int)path.size();
    for(int i = 0 ;i < (int)path.size();i++){
        if(a[path[i]] > b[path[i]]){
            swap(a[path[i]] , b[path[i]]);
        }
        cur += a[path[i]];
        done[path[i]] = 1;
        val = b[path[i]] - a[path[i]];
        q2.push(make_pair(-val * 2, make_pair(0 , path[i])));
    }


    for(int i = 0 ;i < n;i++){
        if(done[i]) continue;
        if(a[i] > b[i]) swap(a[i] , b[i]);
        if(a[i] * 2 < b[i])
            q2.push(make_pair(-a[i] * 2 , make_pair(0 , i)));
        else
            q2.push(make_pair(-b[i] , make_pair(1 , i)));
    }
    k = K;
    if(cur > k)
        return ans;
    int idx;
    while((int)q2.size() > 0){
        idx = q2.top().second.second;
        if(q2.top().second.first == 1){
            q2.pop();
            if(cur + b[idx] > k){
                q2.push(make_pair(-a[idx] * 2,  make_pair(0 , idx)));
                continue;
            }
            cur += b[idx];
            ans2 += 2;
            done[idx] = 2;
            continue;
        }
        q2.pop();
        if(done[idx] == 0){
            if(cur + a[idx] <= k){
                cur += a[idx];
                done[idx] = 1;
                q2.push(make_pair((a[idx] - b[idx]) * 2 , make_pair(0 , idx)));
                ans2++;
            }
        }
        else{
            if(cur + b[idx] - a[idx] <= k){
                cur += b[idx] - a[idx];
                done[idx] = 2;
                ans2++;
            }
        }
    }

    //cout << ans2 << " " << cur << endl;

    return max(ans , ans2);
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 121 ms 34340 KB Output is correct
2 Correct 120 ms 40360 KB Output is correct
3 Correct 60 ms 7588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -