답안 #1056736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056736 2024-08-13T10:47:40 Z TheQuantiX 봉쇄 시간 (IOI23_closing) C++17
8 / 100
1000 ms 36288 KB
#include "closing.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll INF = 1000000000000000000LL;

ll n, m, q, k, x, y, a, b, c, d;
// unordered_map<ll, ll> G1[200000];
vector< pair<ll, ll> > G[200000];

void dfs(ll x, vector<ll> &dist, ll d) {
    // cout << "Enter " << x << endl;
    // cout << '\t' << dist[x] << ' ' << d << endl;
    dist[x] = d;
    for (auto i : G[x]) {
        if (dist[i.first] == INF) {
            dfs(i.first, dist, d + i.second);
        }
    }
    // cout << "Exit " << x << endl;
}

int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    x = X;
    y = Y;
    k = K;
    for (auto i = 0; i < n - 1; i++) {
        // G[U[i]][V[i]] = W[i];
        // G[V[i]][U[i]] = W[i];
        G[U[i]].push_back({V[i], W[i]});
        G[V[i]].push_back({U[i], W[i]});
    }
    vector<ll> dist1(n, INF), dist2(n, INF);
    dfs(x, dist1, 0);
    dfs(y, dist2, 0);
    if (dist1[y] > k * 2) {
        vector<ll> vec;
        for (int i = 0; i < n; i++) {
            // cout << dist1[i] << ' ';
            vec.push_back(dist1[i]);
        }
        // cout << '\n';
        for (int i = 0; i < n; i++) {
            vec.push_back(dist2[i]);
        }
        sort(vec.begin(), vec.end());
        ll cnt = 0;
        for (auto i : vec) {
            // cout << i << '\n';
            if (k >= i) {
                cnt++;
                k -= i;
            }
            else {
                break;
            }
        }
        for (auto i = 0; i < n; i++) {
            // G[U[i]][V[i]] = W[i];
            // G[V[i]][U[i]] = W[i];
            G[i].clear();
        }
        return cnt;
    }
    ll cnt = 2;
    vector<ll> alr(n, 0);
    array< vector<ll>, 2 > vis;
    vis[0].resize(n);
    vis[1].resize(n);
    set< pair< ll, pair<ll, ll> > > st;
    for (auto i : G[x]) {
        st.insert({dist1[i.first], {i.first, 0}});
    }
    for (auto i : G[y]) {
        st.insert({dist2[i.first], {i.first, 1}});
    }
    vis[0][x] = 1;
    vis[1][y] = 1;
    while (st.size() > 0) {
        auto p = *st.begin();
        // cout << p.first << ' ' << p.second.first << ' ' << p.second.second << endl;
        // for (auto i : alr) {
        //     cout << i << ' ';
        // }
        // cout << '\n';
        st.erase(p);
        if (alr[p.second.first] == 0 && (p.second.first != x && p.second.first != y) && st.count({(p.second.second == 0 ? dist2[p.second.first] : dist1[p.second.first]), {p.second.first, 1 - p.second.second}})) {
            st.erase({(p.second.second == 0 ? dist2[p.second.first] : dist1[p.second.first]), {p.second.first, 1 - p.second.second}});
            st.insert({(p.second.second == 0 ? dist2[p.second.first] : dist1[p.second.first]) - p.first, {p.second.first, 1 - p.second.second}});
        }
        if (k < p.first) {
            break;
        }
        cnt++;
        k -= p.first;
        alr[p.second.first] += p.first;
        for (auto i : G[p.second.first]) {
            if (vis[p.second.second][i.first]) {
                continue;
            }
            st.insert({(p.second.second == 0 ? dist1[i.first] : dist2[i.first]) - alr[i.first], {i.first, p.second.second}});
        }
    }
    for (auto i = 0; i < n; i++) {
        // G[U[i]][V[i]] = W[i];
        // G[V[i]][U[i]] = W[i];
        G[i].clear();
    }
    return cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 32184 KB Output is correct
2 Correct 101 ms 36288 KB Output is correct
3 Correct 45 ms 7512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Execution timed out 1092 ms 4956 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Execution timed out 1092 ms 4956 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Execution timed out 1092 ms 4956 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Execution timed out 1092 ms 4956 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Execution timed out 1092 ms 4956 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Execution timed out 1092 ms 4956 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Execution timed out 1092 ms 4956 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Execution timed out 1092 ms 4956 KB Time limit exceeded
4 Halted 0 ms 0 KB -