답안 #113704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113704 2019-05-28T00:44:31 Z zoooma13 통행료 (IOI18_highway) C++14
51 / 100
326 ms 13780 KB
#include "highway.h"
#include "bits/stdc++.h"
using namespace std;

#define MAX_N 90004

//#include "grader.cpp"

int n ,m;
vector <pair <int ,int>> adj[MAX_N];

int par[MAX_N];
vector <pair<int ,int>> nodes;
void bfs(int s){
    nodes.clear();

    queue <pair<int,int>> nxt;
    nxt.push({s ,par[s]});

    while(!nxt.empty()){
        int u = nxt.front().first ,f = nxt.front().second; nxt.pop();
          //  cout << u << endl;
        nodes.push_back({u ,f});
        for(auto e : adj[u])
            nxt.push(e);
    }
}
/**
4 4 1 3 1 3
0 1
0 2
0 3
1 2
*/
int solve(int u ,long long dist){
    bfs(u);
    int st = 0 ,en = nodes.size()-1 ,mid;
    while(st < en){
        mid = (st+en+1)>>1;
        vector <int> w(m ,0);
        for(int i=mid; i<=en; i++)
            w[nodes[i].second] = 1;
        if(ask(w) != dist)
            st = mid;
        else
            en = mid-1;
    }
    return nodes[st].first;
}

vector <pair<int ,int>> t_adj[MAX_N];
void get_bfs_tree(int s){
    vector <bool> vis(n); vis[s] = 1;
    queue <int> nxt; nxt.push(s);
    while(!nxt.empty()){
        int u = nxt.front(); nxt.pop();
        for(auto e : adj[u])
            if(!vis[e.first]){
                vis[e.first] = 1;
                nxt.push(e.first);

                t_adj[u].push_back(e);
                par[e.first] = e.second;
            }
    }
    for(int i=0; i<n; i++)
        swap(adj[i] ,t_adj[i]);
}

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

    long long dist = ask(vector<int>(m ,0));
    int st = 0 ,en = m ,mid;
    while(st < en){
        mid = (st+en)>>1;
        vector <int> w(m ,0);
        for(int i=st; i<=mid; i++)
            w[i] = 1;
        if(ask(w) != dist)
            en = mid;
        else
            st = mid+1;
    }

    get_bfs_tree(U[en]);
    par[U[en]] = en;
    adj[U[en]].erase(find(adj[U[en]].begin() ,adj[U[en]].end() ,make_pair(V[en] ,en)));

    int s = solve(U[en] ,dist);
    int t = solve(V[en] ,dist);
    //cout << s << ' ' << t << endl;
    answer(s ,t);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4600 KB Output is correct
2 Correct 6 ms 4552 KB Output is correct
3 Correct 6 ms 4432 KB Output is correct
4 Correct 5 ms 4548 KB Output is correct
5 Correct 6 ms 4432 KB Output is correct
6 Correct 5 ms 4552 KB Output is correct
7 Correct 6 ms 4600 KB Output is correct
8 Correct 5 ms 4472 KB Output is correct
9 Correct 6 ms 4520 KB Output is correct
10 Correct 6 ms 4600 KB Output is correct
11 Correct 6 ms 4600 KB Output is correct
12 Correct 6 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4600 KB Output is correct
2 Correct 26 ms 5496 KB Output is correct
3 Correct 220 ms 12896 KB Output is correct
4 Correct 206 ms 12924 KB Output is correct
5 Correct 213 ms 12904 KB Output is correct
6 Correct 213 ms 12892 KB Output is correct
7 Correct 206 ms 12880 KB Output is correct
8 Correct 209 ms 12896 KB Output is correct
9 Correct 196 ms 12904 KB Output is correct
10 Correct 211 ms 12904 KB Output is correct
11 Correct 218 ms 12892 KB Output is correct
12 Correct 223 ms 13504 KB Output is correct
13 Correct 254 ms 13504 KB Output is correct
14 Correct 237 ms 13500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 5544 KB Output is correct
2 Correct 36 ms 6448 KB Output is correct
3 Correct 62 ms 7356 KB Output is correct
4 Correct 175 ms 12888 KB Output is correct
5 Correct 171 ms 12944 KB Output is correct
6 Correct 163 ms 13152 KB Output is correct
7 Correct 163 ms 13508 KB Output is correct
8 Correct 178 ms 13136 KB Output is correct
9 Correct 165 ms 13464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4600 KB Output is correct
2 Correct 25 ms 5412 KB Output is correct
3 Correct 145 ms 11036 KB Output is correct
4 Correct 198 ms 12896 KB Output is correct
5 Correct 227 ms 12900 KB Output is correct
6 Correct 204 ms 12896 KB Output is correct
7 Correct 176 ms 12912 KB Output is correct
8 Correct 210 ms 12892 KB Output is correct
9 Correct 245 ms 12908 KB Output is correct
10 Correct 178 ms 12900 KB Output is correct
11 Correct 202 ms 13504 KB Output is correct
12 Correct 246 ms 13120 KB Output is correct
13 Correct 256 ms 13508 KB Output is correct
14 Correct 231 ms 12948 KB Output is correct
15 Correct 165 ms 12892 KB Output is correct
16 Correct 190 ms 12900 KB Output is correct
17 Correct 254 ms 13504 KB Output is correct
18 Correct 196 ms 13500 KB Output is correct
19 Correct 201 ms 12836 KB Output is correct
20 Correct 210 ms 13484 KB Output is correct
21 Correct 178 ms 12800 KB Output is correct
22 Correct 174 ms 12800 KB Output is correct
23 Correct 190 ms 11764 KB Output is correct
24 Correct 205 ms 11832 KB Output is correct
25 Correct 224 ms 13460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 5464 KB Output is correct
2 Correct 31 ms 5500 KB Output is correct
3 Correct 225 ms 13260 KB Output is correct
4 Correct 245 ms 13560 KB Output is correct
5 Incorrect 326 ms 13780 KB Output is incorrect: {s, t} is wrong.
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 5464 KB Output is correct
2 Correct 30 ms 5580 KB Output is correct
3 Correct 237 ms 12656 KB Output is correct
4 Incorrect 244 ms 13576 KB Output is incorrect: {s, t} is wrong.
5 Halted 0 ms 0 KB -