답안 #118790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118790 2019-06-19T18:13:07 Z someone_aa 통행료 (IOI18_highway) C++17
6 / 100
205 ms 20376 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 = 150100;
int n, m;
vector<int>w;
vector<int>gs[maxn];
vector<pair<int,int> > g[maxn];

vector<int>gt[maxn];

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

ll dista;
int type[maxn];
bool important[maxn];

vector<pair<int,int> > st[2];

void bfs(int u, int v) {
    visited[u] = visited[v] = true;
    queue<pair<int,int> > q;

    type[u] = 0;
    type[v] = 1;
    q.push(mp(u, 0));
    q.push(mp(v, 1));

    pind[u] = pind[v] = -1;

    st[0].pb(mp(u, x));
    st[1].pb(mp(v, x));

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

        for(auto i:g[curr]) {
            int ni = i.first, nind = i.second;
            if(visited[ni]) continue;

            visited[ni] = true;
            pind[ni] = nind;
            important[nind] = true;

            q.push(mp(ni, currtype));
            st[currtype].pb(mp(ni, nind));
        }
    }
}

int solve(int root, int d) {
    int li = 0;
    int ri = st[d].size() - 1;

    int answ = li;

    //cout<<d<<": \n";

    while(li <= ri) {
        int mid = (li + ri) / 2;

        vector<int>w(m, 0);
        for(int i=mid;i<st[d].size();i++) {
            w[st[d][i].second] = 1;
        }

        for(int i=0;i<m;i++) {
            if(!important[i]) w[i] = 1;
        }

        ll currdist = ask(w);
        //cout<<mid<<": "<<currdist<<"\n";
        if(currdist == dista) {
            ri = mid - 1;
        }
        else {
            li = mid + 1;
            answ = max(answ, mid);
        }

    }

    return st[d][answ].first;
}

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++) {
        //ind[mp(U[i], V[i])] = ind[mp(V[i], U[i])] = i;
        gs[U[i]].pb(V[i]);
        gs[V[i]].pb(U[i]);

        g[U[i]].pb(mp(V[i], i));
        g[V[i]].pb(mp(U[i], i));

        w.pb(0);
    }

    dista = ask(w);
    while(li <= ri) {
        int mid = (li + ri) / 2;

        for(int i=0;i<mid;i++) {
            w[i] = 1;
        }

        ll currdist = ask(w);

        //cout<<li<<", "<<ri<<" mid: "<<mid<<" --> "<<currdist<<"\n";

        for(int i=0;i<mid;i++) {
            w[i] = 0;
        }

        if(currdist == dista) {
            li = mid + 1;
            x = max(x, mid);
        }
        else {
            ri = mid - 1;
        }

    }

    x = li;
    int u = U[x], v = V[x];
    important[x] = true;

    bfs(u, v);
    //preprocess();

    //memset(visited,false,sizeof(visited));
    int xx = solve(u, 0);
    int yy = solve(v, 1);
    answer(xx, yy);
}

Compilation message

highway.cpp: In function 'int solve(int, int)':
highway.cpp:70:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=mid;i<st[d].size();i++) {
                       ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 10984 KB Output is correct
2 Incorrect 12 ms 10920 KB Output is incorrect: {s, t} is wrong.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 10920 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 12000 KB Output is correct
2 Correct 61 ms 12960 KB Output is correct
3 Correct 73 ms 14000 KB Output is correct
4 Correct 188 ms 19960 KB Output is correct
5 Correct 196 ms 20012 KB Output is correct
6 Correct 186 ms 20376 KB Output is correct
7 Correct 205 ms 20016 KB Output is correct
8 Correct 197 ms 19984 KB Output is correct
9 Correct 183 ms 20276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 11072 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 12000 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 12024 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -