답안 #864064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864064 2023-10-21T19:57:18 Z VMaksimoski008 봉쇄 시간 (IOI23_closing) C++17
0 / 100
162 ms 30868 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Node = array<ll, 3>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int n;
vector<vector<pii> > graph;
vector<int> dist1, dist2;

void dfs(int u, int p, int a, int d) {
    if(a == 1) dist1[u] = d;
    else dist2[u] = d;

    for(pii &next : graph[u]) {
        int v = next.first;
        int w = next.second;
        if(v == p) continue;
        dfs(v, u, a, d + w);
    }
}

int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    graph.clear();
    graph.resize(n);
    dist1.clear();
    dist1.resize(n);
    dist2.clear();
    dist2.resize(n);

    for(int i=0; i<n-1; i++) {
        graph[U[i]].push_back({ V[i], W[i] });
        graph[V[i]].push_back({ U[i], W[i]});
    }

    dfs(X, 0, 1, 0);
    dfs(Y, 0, 2, 0);

    int ans = 0;

    priority_queue<Node, vector<Node>, greater<Node> > pq;
    for(int i=0; i<n; i++) pq.push({ min(dist1[i], dist2[i]), 1, i });

    while(!pq.empty()) {
        int u = pq.top().at(2);
        int t = pq.top().at(1);
        ll d = pq.top().at(0);
        pq.pop();

        if(d <= K) {
            ans++;
            K -= d;
            if(t == 1) {
                pq.push({ max(dist1[u], dist2[u]), 2, u });
            }
        }
    }

    return ans;
}

// int32_t main() {
//     setIO();

//     

//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 162 ms 30868 KB 1st lines differ - on the 1st token, expected: '451', found: '400000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -