답안 #671477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671477 2022-12-13T05:49:59 Z user149 Easter Eggs (info1cup17_eastereggs) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "grader.h"
using namespace std;

using pii=pair<int,int>;

int N;
vector<int> adjlist[555];

bool seen[555];
vector<int> preorder={-1};

void init(){
    fill(seen,seen+555,0);
    fill(adjlist,adjlist+555,(vector<int>){});
    preorder={-1};
}

void dfs(int node){
    seen[node]=1;
    preorder.push_back(node);

    for(int child:adjlist[node]){
        if(!seen[child]) dfs(child);
    }
}

int bsearch(){
    int lo=1;
    int hi=N;

    vector<int> query_vector; // always a prefix [1..i]

    while(lo!=hi){
        int mid=(lo+hi)/2;
        while(query_vector[query_vector.size()-1]>lo) query_vector.pop_back();

        for(int i=lo+1;i<=mid;i++){
            query_vector.push_back(i);
        }

        if(query(query_vector)) hi=mid;
        else lo=mid+1;
    }

    return lo;
}

int findEgg(int _N, vector<pii> edges){
    N=_N;
    init();
    for(pii i:edges){
        int a,b;
        tie(a,b)=i;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    dfs(1);

    return bsearch();
}

    for(int child:adjlist[node]){
        if(!seen[child]) dfs(child);
    }
}

int bsearch(){
    int lo=1;
    int hi=N;

    vector<int> query_vector; // always a prefix [1..i]

    while(lo!=hi){
        int mid=(lo+hi)/2;
        while(query_vector[query_vector.size()-1]>lo) query_vector.pop_back();

        for(int i=lo+1;i<=mid;i++){
            query_vector.push_back(i);
        }

        if(query(query_vector)) hi=mid;
        else lo=mid+1;
    }

    return lo;
}

int findEgg(int _N, vector<pii> edges){
    N=_N;
    init();
    for(pii i:edges){
        int a,b;
        tie(a,b)=i;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    dfs(1);

    return bsearch();
}

Compilation message

eastereggs.cpp:63:5: error: expected unqualified-id before 'for'
   63 |     for(int child:adjlist[node]){
      |     ^~~
eastereggs.cpp:66:1: error: expected declaration before '}' token
   66 | }
      | ^
eastereggs.cpp:68:5: error: redefinition of 'int bsearch()'
   68 | int bsearch(){
      |     ^~~~~~~
eastereggs.cpp:28:5: note: 'int bsearch()' previously defined here
   28 | int bsearch(){
      |     ^~~~~~~
eastereggs.cpp:89:5: error: redefinition of 'int findEgg(int, std::vector<std::pair<int, int> >)'
   89 | int findEgg(int _N, vector<pii> edges){
      |     ^~~~~~~
eastereggs.cpp:49:5: note: 'int findEgg(int, std::vector<std::pair<int, int> >)' previously defined here
   49 | int findEgg(int _N, vector<pii> edges){
      |     ^~~~~~~