답안 #291039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291039 2020-09-04T15:50:47 Z evpipis 통행료 (IOI18_highway) C++11
100 / 100
510 ms 14484 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef long long ll;

const int len = 2e5+5;
ii edge[len];
int n, m, vis[len];
ll dis;
vector<ii> adj[len];

void find_bridge(int &x, int &y){
    int l = 0, r = m-1;
    while (l < r){
        int mid = (l+r)/2;

        vector<int> temp(m, 0);
        for (int j = 0; j <= mid; j++)
            temp[j] = 1;

        if (ask(temp) > dis)
            r = mid;
        else
            l = mid+1;
    }

    x = edge[l].fi;
    y = edge[l].se;
}

void build_tree(int x, int y, vector<int> &order_x, vector<int> &order_y){
    queue<int> myq;
    vis[x] = 1, vis[y] = 2;
    myq.push(x), myq.push(y);

    while (!myq.empty()){
        int u = myq.front();
        myq.pop();

        if (vis[u] == 1)
            order_x.pb(u);
        else
            order_y.pb(u);

        for (auto v: adj[u]){
            if (vis[v.fi]) continue;

            vis[v.fi] = vis[u];
            myq.push(v.fi);
        }
    }

    reverse(order_x.begin(), order_x.end());
    reverse(order_y.begin(), order_y.end());
}

void find_ans(vector<int> order_x, vector<int> order_y, int &x, int &y){
    int l = 0, r = order_x.size()-1;
    while (l < r){
        int mid = (l+r)/2;

        vector<int> temp(m, 0);
        for (int j = 0; j <= mid; j++)
            for (auto v: adj[order_x[j]])
                temp[v.se] = 1;

        if (ask(temp) > dis)
            r = mid;
        else
            l = mid+1;
    }

    x = order_x[l];

    l = 0, r = order_y.size()-1;
    while (l < r){
        int mid = (l+r)/2;

        vector<int> temp(m, 0);
        for (int j = 0; j <= mid; j++)
            for (auto v: adj[order_y[j]])
                temp[v.se] = 1;

        if (ask(temp) > dis)
            r = mid;
        else
            l = mid+1;
    }

    y = order_y[l];
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
    n = N, m = U.size();

    for (int i = 0; i < m; i++){
        int u = U[i]+1, v = V[i]+1;
        edge[i] = mp(u, v);
        adj[u].pb(mp(v, i));
        adj[v].pb(mp(u, i));
    }

    dis = ask(vector<int>(m, 0));

    int x, y;
    find_bridge(x, y);

    //printf("bridge: x = %d, y = %d\n", x, y);

    vector<int> order_x, order_y;
    build_tree(x, y, order_x, order_y);

    int st, en;
    find_ans(order_x, order_y, st, en);
    //printf("st = %d, en = %d\n", st, en);

    answer(st-1, en-1);
}
/*
4 4 1 3 1 3
0 1
0 2
0 3
1 2
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 5088 KB Output is correct
9 Correct 4 ms 5088 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 4 ms 5088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 20 ms 5880 KB Output is correct
3 Correct 284 ms 11984 KB Output is correct
4 Correct 267 ms 12124 KB Output is correct
5 Correct 234 ms 11988 KB Output is correct
6 Correct 158 ms 12016 KB Output is correct
7 Correct 239 ms 12024 KB Output is correct
8 Correct 310 ms 12216 KB Output is correct
9 Correct 312 ms 11996 KB Output is correct
10 Correct 260 ms 11996 KB Output is correct
11 Correct 331 ms 11612 KB Output is correct
12 Correct 285 ms 11624 KB Output is correct
13 Correct 318 ms 11576 KB Output is correct
14 Correct 275 ms 11552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5760 KB Output is correct
2 Correct 31 ms 6620 KB Output is correct
3 Correct 44 ms 7468 KB Output is correct
4 Correct 179 ms 11640 KB Output is correct
5 Correct 173 ms 11568 KB Output is correct
6 Correct 155 ms 11732 KB Output is correct
7 Correct 143 ms 11452 KB Output is correct
8 Correct 169 ms 11632 KB Output is correct
9 Correct 179 ms 11556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5120 KB Output is correct
2 Correct 19 ms 5792 KB Output is correct
3 Correct 233 ms 10492 KB Output is correct
4 Correct 279 ms 11984 KB Output is correct
5 Correct 322 ms 11988 KB Output is correct
6 Correct 368 ms 12100 KB Output is correct
7 Correct 354 ms 12184 KB Output is correct
8 Correct 362 ms 12072 KB Output is correct
9 Correct 254 ms 12040 KB Output is correct
10 Correct 254 ms 12148 KB Output is correct
11 Correct 309 ms 11548 KB Output is correct
12 Correct 248 ms 11604 KB Output is correct
13 Correct 273 ms 11696 KB Output is correct
14 Correct 322 ms 11572 KB Output is correct
15 Correct 294 ms 12056 KB Output is correct
16 Correct 314 ms 12016 KB Output is correct
17 Correct 275 ms 11492 KB Output is correct
18 Correct 339 ms 11488 KB Output is correct
19 Correct 366 ms 12100 KB Output is correct
20 Correct 388 ms 11448 KB Output is correct
21 Correct 172 ms 12712 KB Output is correct
22 Correct 178 ms 12780 KB Output is correct
23 Correct 166 ms 12240 KB Output is correct
24 Correct 173 ms 12144 KB Output is correct
25 Correct 168 ms 11660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6024 KB Output is correct
2 Correct 23 ms 5880 KB Output is correct
3 Correct 223 ms 12508 KB Output is correct
4 Correct 309 ms 13056 KB Output is correct
5 Correct 414 ms 14224 KB Output is correct
6 Correct 447 ms 14104 KB Output is correct
7 Correct 452 ms 14344 KB Output is correct
8 Correct 437 ms 14376 KB Output is correct
9 Correct 197 ms 12020 KB Output is correct
10 Correct 225 ms 12496 KB Output is correct
11 Correct 186 ms 12888 KB Output is correct
12 Correct 426 ms 13824 KB Output is correct
13 Correct 311 ms 14224 KB Output is correct
14 Correct 386 ms 14316 KB Output is correct
15 Correct 451 ms 14232 KB Output is correct
16 Correct 289 ms 13128 KB Output is correct
17 Correct 245 ms 12400 KB Output is correct
18 Correct 276 ms 12532 KB Output is correct
19 Correct 196 ms 12464 KB Output is correct
20 Correct 293 ms 12632 KB Output is correct
21 Correct 440 ms 14236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 5880 KB Output is correct
2 Correct 21 ms 6080 KB Output is correct
3 Correct 390 ms 12636 KB Output is correct
4 Correct 364 ms 12920 KB Output is correct
5 Correct 398 ms 13116 KB Output is correct
6 Correct 319 ms 14084 KB Output is correct
7 Correct 330 ms 12500 KB Output is correct
8 Correct 419 ms 12872 KB Output is correct
9 Correct 486 ms 12992 KB Output is correct
10 Correct 447 ms 14208 KB Output is correct
11 Correct 435 ms 14264 KB Output is correct
12 Correct 499 ms 14096 KB Output is correct
13 Correct 205 ms 12916 KB Output is correct
14 Correct 214 ms 12508 KB Output is correct
15 Correct 230 ms 12856 KB Output is correct
16 Correct 224 ms 12516 KB Output is correct
17 Correct 261 ms 12876 KB Output is correct
18 Correct 251 ms 12580 KB Output is correct
19 Correct 424 ms 13792 KB Output is correct
20 Correct 430 ms 14096 KB Output is correct
21 Correct 510 ms 14456 KB Output is correct
22 Correct 495 ms 14256 KB Output is correct
23 Correct 415 ms 14328 KB Output is correct
24 Correct 370 ms 14300 KB Output is correct
25 Correct 442 ms 14260 KB Output is correct
26 Correct 429 ms 14236 KB Output is correct
27 Correct 241 ms 12612 KB Output is correct
28 Correct 275 ms 12304 KB Output is correct
29 Correct 291 ms 12732 KB Output is correct
30 Correct 163 ms 12416 KB Output is correct
31 Correct 224 ms 12424 KB Output is correct
32 Correct 230 ms 12460 KB Output is correct
33 Correct 187 ms 12604 KB Output is correct
34 Correct 269 ms 12356 KB Output is correct
35 Correct 248 ms 12460 KB Output is correct
36 Correct 271 ms 12292 KB Output is correct
37 Correct 266 ms 12648 KB Output is correct
38 Correct 154 ms 12420 KB Output is correct
39 Correct 398 ms 14484 KB Output is correct
40 Correct 411 ms 14284 KB Output is correct
41 Correct 238 ms 14120 KB Output is correct
42 Correct 400 ms 14292 KB Output is correct