Submission #965396

# Submission time Handle Problem Language Result Execution time Memory
965396 2024-04-18T12:37:13 Z Warinchai Highway Tolls (IOI18_highway) C++14
0 / 100
15 ms 2904 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>>adj[100000];
void dfs(int u,vector<int>&x,vector<int>&nodes,int p,int val){
    x.push_back(val);
    nodes.push_back(u);
    for(auto v:adj[u])if(v.first!=p)dfs(v.first,x,nodes,u,v.second);
}
void subtree(int n,vector<int>u,vector<int>v,int a,int b,int cost){
    int st=0,en=u.size()-1,ans=0;
    while(st<=en){
        int m=(st+en)/2;
        vector<int>temp;
        for(int i=0;i<m;i++)temp.push_back(1);
        for(int i=m;i<n;i++)temp.push_back(0);
        if(ask(temp)>cost){
            en=m-1;
            ans=m;
        }else{
            st=m+1;
        }
    }
    int bg=u[ans];
    int ed=v[ans];
    vector<int>temp;
    vector<int>side1;
    vector<int>side2;
    vector<int>node1;
    vector<int>node2;
    for(int i=0;i<n;i++)temp.push_back(0);
    dfs(bg,side1,node1,ed,ans);
    dfs(ed,side2,node2,bg,ans);
    for(auto x:side1)temp[x]=1;
    int cost1=ask(temp);
    for(auto x:side1)temp[x]=0;
    for(auto x:side2)temp[x]=1;
    int cost2=ask(temp);
    for(int i=0;i<n;i++)temp[i]=0;
    int n1,n2;
    st=0,en=side1.size();
    for(int i=0;i<n;i++)temp[i]=0;
    while(st<=en){
        int m=(st+en)/2;
        for(int i=0;i<m;i++)temp[side1[i]]=1;
        if(ask(temp)<=cost1){
            st=m+1;
            n1=m;
        }else{
            en=m-1;
        }
        for(int i=0;i<m;i++)temp[side1[i]]=0;
    }
    st=0,en=side2.size();
    while(st<=en){
        int m=(st+en)/2;
        for(int i=0;i<m;i++)temp[side2[i]]=1;
        if(ask(temp)<=cost2){
            st=m+1;
            n2=m;
        }else{
            en=m-1;
        }
        for(int i=0;i<m;i++)temp[side2[i]]=0;
    }
    answer(node1[n1],node2[n2]);
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    vector<int>temp;
    for(int i=0;i<N;i++)temp.push_back(0);
    if(U.size()!=N-1)return answer(rand()%N,rand()%N);
    else return subtree(N,U,V,A,B,ask(temp));
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:71:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   71 |     if(U.size()!=N-1)return answer(rand()%N,rand()%N);
      |        ~~~~~~~~^~~~~
highway.cpp: In function 'void subtree(int, std::vector<int>, std::vector<int>, int, int, int)':
highway.cpp:66:30: warning: 'n2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |     answer(node1[n1],node2[n2]);
      |                              ^
highway.cpp:66:20: warning: 'n1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |     answer(node1[n1],node2[n2]);
      |                    ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 2860 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2904 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 2904 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -