답안 #918141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918141 2024-01-29T13:15:25 Z Elwino008 Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
12 ms 1252 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

#define endl '\n'
#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
//#define int ll
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
#define all(v) v.begin(), v.end()
#define pss pair<string, string>
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define imp cout<<-1<<endl;
#define flu cout.flush();

int n, used[1055];
vector<int>a[1055];
vector<int>nodes;

void dfs(int node){
    used[node]=1;
    nodes.pb(node);
    for(int i : a[node]){
        if(used[i]==0){
            dfs(i);
        }
    }
}

int findEgg (int N, vector < pair < int, int > > bridges)
{
    for(int i=1; i<=n; i++){
        a[i].clear();
    }
    for(int i=1; i<=n; i++){
        used[i]=0;
    }
    nodes.clear();
    n=N;
    for(pii i : bridges){
        int f=i.F, s=i.S;
        a[f].pb(s);
        a[s].pb(f);
    }
    dfs(1);
    n=N;
    int l=0, r=n-1;
    while(l<r){
        int mid=(l+r)/2;
        vector<int>islands;
        for(int i=0; i<=mid; i++){
            islands.pb(nodes[i]);
        }
        int ans;
        ans=query(islands);
        if(ans==1){
            r=mid;
        }
        else{
            l=mid+1;
        }
        
    }
    return nodes[l];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 1 ms 344 KB Number of queries: 4
4 Correct 1 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 744 KB Number of queries: 8
2 Correct 7 ms 1000 KB Number of queries: 9
3 Correct 12 ms 748 KB Number of queries: 9
4 Correct 11 ms 756 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 520 KB Number of queries: 9
2 Correct 9 ms 1252 KB Number of queries: 9
3 Correct 10 ms 748 KB Number of queries: 9
4 Correct 10 ms 1016 KB Number of queries: 9