답안 #551200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551200 2022-04-20T05:18:13 Z krit3379 Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
23 ms 468 KB
#include<bits/stdc++.h>
using namespace std;
#include"grader.h"
#define N 1000

int id[N],sz;
vector<int> g[N];

void dfs(int s,int f){
    id[++sz]=s;
    for(auto x:g[s]){
        if(x==f)continue;
        dfs(x,s);
    }
}

int findEgg(int n, vector<pair<int,int>> edge){
    int i,l,r,mid,flag;
    for(i=1;i<=n;i++)g[i].clear();
    for(auto [a,b]:edge){
        g[a].push_back(b);
        g[b].push_back(a);
    }
    sz=0;
    dfs(1,0);
    vector<int> v;
    l=1,r=n;
    while(l<r){
        mid=(l+r)/2;
        for(i=1;i<=mid;i++)v.push_back(id[i]);
        flag=query(v);
        if(flag)r=mid;
        else l=mid+1;
        v.clear();
    }
    return id[r];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Correct 1 ms 208 KB Number of queries: 4
3 Correct 2 ms 208 KB Number of queries: 4
4 Correct 1 ms 208 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 352 KB Number of queries: 8
2 Correct 12 ms 356 KB Number of queries: 9
3 Correct 19 ms 336 KB Number of queries: 9
4 Correct 17 ms 360 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 336 KB Number of queries: 9
2 Correct 12 ms 388 KB Number of queries: 9
3 Correct 18 ms 468 KB Number of queries: 9
4 Correct 23 ms 356 KB Number of queries: 9