답안 #970501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970501 2024-04-26T16:04:20 Z jamesbamber 통행료 (IOI18_highway) C++17
51 / 100
140 ms 11972 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    int M = U.size();
    vector<vector<pair<int,int>>> ad(N);
    for(int i=0; i<M; i++){
        ad[U[i]].push_back({V[i], i});
        ad[V[i]].push_back({U[i], i});
    }

    vector<int> up(N, -1), d(N);
    vector<int> order;
    auto bfs = [&](int s){
        vector<int> vis(N);
        queue<int> q; q.push(s);
        up.assign(N, -1), d.assign(N, 0);
        order.clear();
        vis[s] = 1;
        while(q.size()){
            int v = q.front(); q.pop();
            order.push_back(v);
            for(auto [u, id]: ad[v]){
                if(vis[u]) continue;
                vis[u] = 1;
                d[u] = d[v]+1;
                up[u] = id;
                q.push(u);
            }
        }
    };

    auto ask_depth = [&](int t){
        vector<int> w(M);
        for(int i=0; i<N; i++){
            if(d[i] <= t and up[i] != -1) w[up[i]] = 1;
        }
        return ask(w);
    };

    bfs(0);
    ll dist = ask_depth(0)/A;

    int l = 0, r = N;
    while(r-l > 1){
        int m = (l+r)/2;
        if(ask_depth(m) != dist*B) l = m;
        else r = m;
    }
    int mxdepth = r;


    auto ask_vec = [&](vector<pair<int,int>> &vec, int t){
        vector<int> w(M);
        for(int i=0; i<t; i++) 
            if(vec[i].second != -1) w[vec[i].second] = 1;
        return ask(w);
    };

    vector<pair<int,int>> susdepth;
    for(int i=0; i<N; i++){
        if(d[i] == mxdepth) susdepth.push_back({i, up[i]});
    }


    l = 0, r = susdepth.size();
    while(r-l > 1){
        int m = (l+r)/2;
        if(ask_vec(susdepth, m) == dist*A) l = m;
        else r = m;
    }
    int ans1 = susdepth[l].first;

    bfs(ans1);
    vector<pair<int,int>> ordersus;
    for(int x: order) ordersus.push_back({x, up[x]});

    l = 0, r = N;
    while(r-l > 1){
        int m = (l+r)/2;
        if(ask_vec(ordersus, m) != dist*B) l = m;
        else r = m;
    }
    int ans2 = ordersus[l].first;
    answer(ans1, ans2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 444 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 444 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 532 KB Output is correct
2 Correct 14 ms 1580 KB Output is correct
3 Correct 90 ms 10052 KB Output is correct
4 Correct 114 ms 10296 KB Output is correct
5 Correct 95 ms 10040 KB Output is correct
6 Correct 119 ms 9844 KB Output is correct
7 Correct 102 ms 10148 KB Output is correct
8 Correct 102 ms 10040 KB Output is correct
9 Correct 135 ms 10072 KB Output is correct
10 Correct 101 ms 10056 KB Output is correct
11 Correct 118 ms 10148 KB Output is correct
12 Correct 105 ms 9472 KB Output is correct
13 Correct 114 ms 9728 KB Output is correct
14 Correct 102 ms 9488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1620 KB Output is correct
2 Correct 21 ms 2540 KB Output is correct
3 Correct 25 ms 3416 KB Output is correct
4 Correct 120 ms 9836 KB Output is correct
5 Correct 74 ms 9468 KB Output is correct
6 Correct 88 ms 9472 KB Output is correct
7 Correct 92 ms 9472 KB Output is correct
8 Correct 81 ms 9468 KB Output is correct
9 Correct 79 ms 9464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 528 KB Output is correct
2 Correct 10 ms 1680 KB Output is correct
3 Correct 66 ms 8180 KB Output is correct
4 Correct 91 ms 9900 KB Output is correct
5 Correct 93 ms 9912 KB Output is correct
6 Correct 140 ms 10048 KB Output is correct
7 Correct 93 ms 10156 KB Output is correct
8 Correct 86 ms 10024 KB Output is correct
9 Correct 102 ms 10148 KB Output is correct
10 Correct 121 ms 10272 KB Output is correct
11 Correct 100 ms 9728 KB Output is correct
12 Correct 94 ms 9468 KB Output is correct
13 Correct 100 ms 9472 KB Output is correct
14 Correct 126 ms 9480 KB Output is correct
15 Correct 127 ms 9896 KB Output is correct
16 Correct 87 ms 9908 KB Output is correct
17 Correct 104 ms 9484 KB Output is correct
18 Correct 106 ms 9464 KB Output is correct
19 Correct 88 ms 9908 KB Output is correct
20 Correct 109 ms 9692 KB Output is correct
21 Correct 90 ms 11972 KB Output is correct
22 Correct 107 ms 11744 KB Output is correct
23 Correct 93 ms 10476 KB Output is correct
24 Correct 92 ms 10592 KB Output is correct
25 Correct 105 ms 9440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 2600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 2588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -