답안 #116982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116982 2019-06-14T10:47:17 Z pzdba 통행료 (IOI18_highway) C++14
0 / 100
26 ms 5160 KB
#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
vector<pii> g[90005], g2[90005];
bool vis[90005];
int arr[2][90005];
int par[90005];
int k = 1;
void dfs(int u, int p, int j, int d, int t){
    par[u] = j;
    arr[t][k++] = u;
    for(int i=0;i<g2[u].size();i++){
        int v = g2[u][i].first, j = g2[u][i].second;
        if(v == p) continue;
        dfs(v, u, j, d+1, t);
    }
}
void find_pair(int n, std::vector<int> U, std::vector<int> V, int a, int b){
    int s, t;
    int m = U.size();
    for(int i=0;i<m;i++){
        int a = U[i], b = V[i];
        g[a].push_back(pii(b, i));
        g[b].push_back(pii(a, i));
    }
    vector<int> w;
    w.resize(m);
    LL base = ask(w);
    int lo = 0, hi = m-1, j = 0;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        for(int i=0;i<m;i++) w[i] = 0;
        for(int i=0;i<=mid;i++) w[i] = 1;
        LL tmp = ask(w);
        if(tmp > base) j = mid, hi = mid-1;
        else lo = mid+1;
    }
    int u = U[j], v = V[j];
    vis[u] = 1;
    vis[v] = 1;
    queue<int> q;
    q.push(u);
    q.push(v);
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(int i=0;i<g[u].size();i++){
            int v = g[u][i].first, j = g[u][i].second;
            if(vis[v]) continue;
            vis[v] = 1;
            g2[u].push_back(pii(v, j));
            g2[v].push_back(pii(u, j));
        }
    }
    k = 1;
    dfs(u, -1, 0, 0, 0);
    int sz1 = k-1;

    k = 1;
    dfs(v, -1, 0, 0, 1);
    int sz2 = k-1;

    s = u, t = v;
    lo = 2, hi = sz1;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        for(int i=0;i<m;i++) w[i] = 0;
        for(int i=mid;i<=sz1;i++){
            int u = arr[0][i];
            w[par[u]] = 1;
        }
        LL tmp = ask(w);
        if(tmp > base) s = arr[0][mid], lo = mid+1;
        else hi = mid-1;
    }
    lo = 2, hi = sz2;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        for(int i=0;i<m;i++) w[i] = 0;
        for(int i=mid;i<=sz2;i++){
            int u = arr[1][i];
            w[par[u]] = 1;
        }
        LL tmp = ask(w);
        if(tmp > base) t = arr[1][mid], lo = mid+1;
        else hi = mid-1;
    }
    answer(s, t);
}

Compilation message

highway.cpp: In function 'void dfs(int, int, int, int, int)':
highway.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<g2[u].size();i++){
                 ~^~~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:49:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<g[u].size();i++){
                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4636 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4520 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 5068 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4644 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 5152 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 5160 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -