답안 #978693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978693 2024-05-09T14:04:08 Z bachhoangxuan 통행료 (IOI18_highway) C++17
0 / 100
14 ms 3704 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
#define pii pair<int,int>
#define fi first
#define se second

int dd[2][maxn],f[2][maxn];
vector<pii> edge[maxn];

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    vector<int> S(2),T(2);
    int M=(int)U.size();
    for(int i=0;i<M;i++){
        edge[U[i]].push_back({V[i],i});
        edge[V[i]].push_back({U[i],i});
    }

    vector<int> w(M,0);
    int dist=ask(w);
    int l=1,r=M;
    while(l<r){
        int mid=(l+r)>>1;
        w.assign(M,0);
        for(int i=0;i<mid;i++) w[i]=1;
        if(ask(w)!=dist) r=mid;
        else l=mid+1;
    }
    S[0]=U[l-1],S[1]=V[l-1];
    for(int i=0;i<=1;i++){
        queue<int> qq;
        for(int u=0;u<N;u++) dd[i][u]=f[i][u]=-1;
        dd[i][S[i]]=0;qq.push(S[i]);
        while(!qq.empty()){
            int u=qq.front();qq.pop();
            for(auto [v,id]:edge[u]) if(dd[i][v]!=-1){
                dd[i][v]=dd[i][u]+1;
                f[i][v]=id;
                qq.push(v);
            }
        }
    }
    vector<vector<int>> cc(2);
    for(int u=0;u<N;u++){
        if(dd[0][u]<dd[1][u]) cc[0].push_back(u);
        else cc[1].push_back(u);
    }

    for(int i=0;i<=1;i++){
        sort(cc[i].begin(),cc[i].end(),[&](int x,int y){
            return dd[i][x]<dd[i][y];
        });
        T[i]=cc[i][0];
        l=1,r=(int)cc[i].size()-1;
        while(l<=r){
            int mid=(l+r)>>1;
            w.assign(M,0);
            for(int j=mid;j<(int)cc[i].size();j++) for(auto [v,id]:edge[cc[i][j]]) w[id]=1;
            if(ask(w)!=dist) T[i]=cc[i][mid],l=mid+1;
            else r=mid-1;
        }
    }
    answer(T[0],T[1]);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2800 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2852 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 3584 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2848 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 3668 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 3704 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -