답안 #462443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
462443 2021-08-10T14:44:44 Z JovanB Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
34 ms 824 KB
#include <bits/stdc++.h>
#include "grader.h"
 
using namespace std;
 
vector <int> ord;
vector <int> graf[20005];
 
void dfs(int v, int par){
    ord.push_back(v);
    for(auto c : graf[v]){
        if(c != par) dfs(c, v);
    }
}
 
int kveri(int x){
    vector <int> qq;
    for(int i=1; i<=x; i++) qq.push_back(ord[i]);
    return query(qq);
}
 
int findEgg (int N, vector < pair < int, int > > bridges)
{
    for(int i=1; i<=N; i++) graf[i].clear();
    ord.clear();
    ord.push_back(0);
    for(auto c : bridges){
        graf[c.first].push_back(c.second);
        graf[c.second].push_back(c.first);
    }
    dfs(1, 0);
    int l = 1, r = N;
    while(l < r){
        int mid = (l+r)/2;
        if(kveri(mid)){
            r = mid;
        }
        else l = mid+1;
    }
    return ord[l];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 712 KB Number of queries: 4
2 Correct 2 ms 712 KB Number of queries: 4
3 Correct 1 ms 712 KB Number of queries: 4
4 Correct 2 ms 712 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 804 KB Number of queries: 8
2 Correct 15 ms 792 KB Number of queries: 9
3 Correct 34 ms 796 KB Number of queries: 9
4 Correct 27 ms 808 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 824 KB Number of queries: 9
2 Correct 18 ms 812 KB Number of queries: 9
3 Correct 16 ms 792 KB Number of queries: 9
4 Correct 30 ms 712 KB Number of queries: 9