| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1139150 | Muhammet | Permutation Recovery (info1cup17_permutation) | C++20 | 0 ms | 0 KiB | 
#include "bits/stdc++.h"
// #include "grader.h"
// #include "grader.cpp"
#define SZ(s) (int)s.size()
using namespace std;
vector <vector <int>> ve;
vector <int> path;
void dfs(int x, int y){
    path.push_back(x);
    for(auto i : ve[x]){
        if(i == y) continue;
        dfs(i,x);
        path.push_back(x);
    }
}
int findEgg (int n, vector < pair < int, int > > briges) {
    ve.resize(n+1);
    for(auto [i,j] : briges){
        ve[i].push_back(j);
        ve[j].push_back(i);
    }
    dfs(1,0);
    int l = 0, r = SZ(path)-1;
    map <int,bool> vis;
    while(l < r){
        int md = (l + r) / 2;
        vis.clear();
        vector <int> qwe;
        for(int i = l; i <= md; i++){
            if(vis.find(path[i]) == vis.end()) qwe.push_back(path[i]), vis[path[i]] = true;
        }
        if(query(qwe)) r = md;
        else l = md+1;
    }
    return path[l];
}
