답안 #839906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839906 2023-08-30T20:46:38 Z mohammad_kilani 봉쇄 시간 (IOI23_closing) C++17
43 / 100
117 ms 40352 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(path[i] , 0)));
    }


    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(i , 0)));
        else
            q2.push(make_pair(-b[i] , make_pair(i , 1)));
    }
    k = K;
    if(cur > k)
        return ans;
    int idx;
    while((int)q2.size() > 0){
        idx = q2.top().second.first;
        if(q2.top().second.second == 1){
            q2.pop();
            if(cur + b[idx] > k){
                q2.push(make_pair(-a[idx] * 2,  make_pair(idx , 0)));
                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(idx , 0)));
                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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 34340 KB Output is correct
2 Correct 117 ms 40352 KB Output is correct
3 Correct 60 ms 7608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 5000 KB Output is correct
15 Correct 2 ms 4964 KB Output is correct
16 Correct 2 ms 5004 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 2 ms 5076 KB Output is correct
21 Correct 2 ms 5024 KB Output is correct
22 Correct 3 ms 5088 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 2 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 5000 KB Output is correct
15 Correct 2 ms 4964 KB Output is correct
16 Correct 2 ms 5004 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
20 Correct 2 ms 5076 KB Output is correct
21 Correct 2 ms 5024 KB Output is correct
22 Correct 3 ms 5088 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 2 ms 5076 KB Output is correct
25 Correct 4 ms 5076 KB Output is correct
26 Correct 4 ms 5572 KB Output is correct
27 Correct 5 ms 5460 KB Output is correct
28 Correct 4 ms 5588 KB Output is correct
29 Correct 4 ms 5588 KB Output is correct
30 Correct 3 ms 5536 KB Output is correct
31 Correct 4 ms 5524 KB Output is correct
32 Correct 4 ms 5544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '9', found: '8'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 5000 KB Output is correct
16 Correct 2 ms 4964 KB Output is correct
17 Correct 2 ms 5004 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '9', found: '8'
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 5000 KB Output is correct
16 Correct 2 ms 4964 KB Output is correct
17 Correct 2 ms 5004 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 2 ms 5076 KB Output is correct
22 Correct 2 ms 5024 KB Output is correct
23 Correct 3 ms 5088 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 2 ms 5076 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '9', found: '8'
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 5000 KB Output is correct
16 Correct 2 ms 4964 KB Output is correct
17 Correct 2 ms 5004 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 2 ms 5076 KB Output is correct
22 Correct 2 ms 5024 KB Output is correct
23 Correct 3 ms 5088 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 2 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 4 ms 5572 KB Output is correct
28 Correct 5 ms 5460 KB Output is correct
29 Correct 4 ms 5588 KB Output is correct
30 Correct 4 ms 5588 KB Output is correct
31 Correct 3 ms 5536 KB Output is correct
32 Correct 4 ms 5524 KB Output is correct
33 Correct 4 ms 5544 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '9', found: '8'
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 5000 KB Output is correct
16 Correct 2 ms 4964 KB Output is correct
17 Correct 2 ms 5004 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 2 ms 5076 KB Output is correct
22 Correct 2 ms 5024 KB Output is correct
23 Correct 3 ms 5088 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 2 ms 5076 KB Output is correct
26 Correct 4 ms 5076 KB Output is correct
27 Correct 4 ms 5572 KB Output is correct
28 Correct 5 ms 5460 KB Output is correct
29 Correct 4 ms 5588 KB Output is correct
30 Correct 4 ms 5588 KB Output is correct
31 Correct 3 ms 5536 KB Output is correct
32 Correct 4 ms 5524 KB Output is correct
33 Correct 4 ms 5544 KB Output is correct
34 Correct 2 ms 4948 KB Output is correct
35 Correct 2 ms 4948 KB Output is correct
36 Incorrect 2 ms 4948 KB 1st lines differ - on the 1st token, expected: '9', found: '8'
37 Halted 0 ms 0 KB -