답안 #1016035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016035 2024-07-07T10:06:10 Z c2zi6 통행료 (IOI18_highway) C++14
12 / 100
125 ms 16976 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "highway.h"

int n, m;
VVPI gpa;
VVPI gpb;
VI depth;
VI parind;
VI par;

VI euler;
void dfs(int u = 0, int p = -1, int pind = -1) {
    if (u) euler.pb(u);
    parind[u] = pind;
    par[u] = p;
    for (auto[v, ind] : gpb[u]) if (ind != pind) {
        depth[v] = depth[u]+1;
        dfs(v, u, ind);
    }
}

void BFS(int r) {
    gpb = VVPI(n);
    queue<int> q;
    VI vis(n);
    q.push(r);
    vis[r] = true;
    while (q.size()) {
        int u = q.front();
        q.pop();
        for (auto[v, ind] : gpa[u]) if (!vis[v]) {
            gpb[u].pb({v, ind});
            gpb[v].pb({u, ind});
            q.push(v);
            vis[v] = true;
        }
    }
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    n = N;
    m = U.size();
    gpa = VVPI(n);
    rep(i, m) {
        gpa[U[i]].pb({V[i], i});
        gpa[V[i]].pb({U[i], i});
    }


    ll base = ask(VI(m));
    int d = base/A;

    int w;
    if (true) {
        //searching for value of w
        auto f = [&](int x) {
            VI W(m);
            replr(u, 0, x) for (auto[v, ind] : gpa[u]) {
                W[ind] = true;
            }
            return ask(W) > base;
        };
        int l = -1, r = n-1;
        while (l+1 < r) {
            int m = (l + r) / 2;
            if (f(m) == 0) l = m;
            else r = m;
        }
        w = r;
    }

    int s;
    if (true) {
        //searching for value of s
        BFS(w);
        depth = parind = par = VI(n);
        euler = VI();
        dfs(w);
        auto f = [&](int x) {
            VI W(m);
            replr(i, 0, x) W[parind[euler[i]]] = true;
            return (ask(W)-base)/(B-A);
        };
        int l = -1, r = m-1;
        while (l+1 < r) {
            int m = (l + r) / 2;
            if (f(m) < d) l = m;
            else r = m;
        }
        s = euler[r];
    }
    int t;
    if (true) {
        //searching for value of t
        BFS(s);
        depth = parind = par = VI(n);
        euler = VI();
        dfs(s);
        VI b;
        rep(u, n) if (depth[u] == d) b.pb(u);
        auto f = [&](int x) {
            VI W(m);
            replr(i, 0, x) W[parind[b[i]]] = true;
            return ask(W) > base;
        };
        int l = -1, r = b.size()-1;
        while (l + 1 < r) {
            int m = (l + r) / 2;
            if (f(m)) r = m;
            else l = m;
        }
        t = b[r];
    }
    answer(s, t);
}

/*ask(VI w);*/
/*answer(int s, int t)*/




Compilation message

highway.cpp: In function 'void dfs(int, int, int)':
highway.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |     for (auto[v, ind] : gpb[u]) if (ind != pind) {
      |              ^
highway.cpp: In function 'void BFS(int)':
highway.cpp:61:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |         for (auto[v, ind] : gpa[u]) if (!vis[v]) {
      |                  ^
highway.cpp: In lambda function:
highway.cpp:88:37: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   88 |             replr(u, 0, x) for (auto[v, ind] : gpa[u]) {
      |                                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 10 ms 2220 KB Output is correct
3 Correct 112 ms 16756 KB Output is correct
4 Correct 123 ms 16760 KB Output is correct
5 Correct 108 ms 16828 KB Output is correct
6 Correct 111 ms 16868 KB Output is correct
7 Correct 120 ms 16784 KB Output is correct
8 Correct 107 ms 16836 KB Output is correct
9 Correct 125 ms 16632 KB Output is correct
10 Correct 111 ms 16812 KB Output is correct
11 Correct 107 ms 16596 KB Output is correct
12 Correct 98 ms 16964 KB Output is correct
13 Correct 104 ms 16976 KB Output is correct
14 Correct 116 ms 16328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 4184 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 3848 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3840 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -