답안 #76992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76992 2018-09-19T20:27:07 Z someone_aa 통행료 (IOI18_highway) C++17
0 / 100
27 ms 3724 KB
#include "highway.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
int n, m;
vector<int>w;
vector<pair<int,int> > g[maxn];

int dist[maxn][2], parent[maxn][2];
bool visited[maxn];

ll dista;

void bfs(int st, int d) {
    memset(visited,false,sizeof(visited));
    queue<int>q;
    q.push(st);

    parent[st][d] = -1;
    visited[st] = true;

    while(!q.empty()) {
        int curr = q.front();
        q.pop();

        for(auto i:g[curr]) {
            if(!visited[i.first]) {
                visited[i.first] = true;
                dist[i.first][d] = dist[curr][d] + 1;
                parent[i.first][d] = i.second;
                q.push(i.first);
            }
        }
    }
}

int solve(vector<int> x, int d) {
    vector<int>w;
    for(int i=0;i<m;i++) w.pb(0);
    vector<pair<int,int> > dists;
    for(int i:x) {
        dists.pb(mp(dist[i][d], i));
    }
    sort(dists.begin(), dists.end());

    //cout<<d<<": ";
    //for(int i:x) cout<<i<<" ";
    //cout<<"\n";
    for(int i=0;i<m;i++) w[i] = 1;
    for(int i:x) if(parent[i][d] != -1) w[parent[i][d]] = 0;

    //for(int i=0;i<m;i++) {
      //  cout<<w[i]<<" ";
    //} cout<<"\n";

    ll dista = ask(w);
    int li=0, ri=dists.size()-1;
    while(li<ri) {
        int mid = (li+ri)/2;

        for(int i=mid+1;i<=ri;i++) {
            if(parent[dists[i].second][d] != -1)
                w[parent[dists[i].second][d]] = 1;
        }
        ll distb = ask(w);

        for(int i=mid+1;i<=ri;i++) {
            if(parent[dists[i].second][d] != -1)
                w[parent[dists[i].second][d]] = 0;
        }

        if(dista == distb) {
            ri = mid;
        }
        else {
            li = mid + 1;
        }
    }
    return x[li];
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    n = N; m = U.size();
    int li=0, ri=m-1;

    for(int i=0;i<m;i++) {
        g[U[i]].pb(mp(V[i], i));
        g[V[i]].pb(mp(U[i], i));
    }

    for(int i=0;i<m;i++) w.pb(0);
    dista = ask(w);

    while(li<ri) {
        int mid = (li+ri)/2;
        for(int i=li;i<=mid;i++) {
            w[i] = 1;
        }
        ll distb = ask(w);
        for(int i=li;i<=mid;i++) {
            w[i] = 0;
        }
        if(dista == distb) {
            li = mid + 1;
        }
        else {
            ri = mid;
        }
    }
    int x = li;
    int u = U[x], v = V[x];
    bfs(u, 0);
    bfs(v, 1);

    vector<int>su, sv;
    for(int i=0;i<n;i++) {
        if(dist[i][0] <= dist[i][1]) {
            su.pb(i);
        }
        else {
            sv.pb(i);
        }
    }

    int xx = solve(su, 0);
    int yy = solve(sv, 1);
    //cout<<xx<<" "<<yy<<"\n";
    answer(xx, yy);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2680 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 2808 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 3716 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2940 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 3724 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 3724 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -