답안 #671445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671445 2022-12-13T05:14:52 Z dooompy Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
22 ms 2712 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

vector<int> adj[100005];

vector<int> straight;

bool able(int m) {
		vector<int> temp;
		for(int i = 0; i <= m; ++i) temp.push_back(straight[i]);
    return query(temp);
}


void dfs(int node, int par = -1) {
    straight.push_back(node);

    for (auto nxt : adj[node]) {
        if (nxt == par) continue;
        dfs(nxt, node);
    }
}

int findEgg (int N, vector < pair < int, int > > bridges)
{
    straight.clear();
    for (int i = 0; i <= N; i++) adj[i].clear();

    for (int i = 0; i < bridges.size(); i++) {
        adj[bridges[i].first].push_back(bridges[i].second);
        adj[bridges[i].second].push_back(bridges[i].first);
    }

    dfs(1);

    int n = straight.size();

    int l = 0, r = n-1;

    int ans = -1;

     
	while(l < r) {
        
        int m = (l + r) >> 1;
		if(able(m)) r = m;
		else l = m + 1;
	}

    return straight[r];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < bridges.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~
eastereggs.cpp:42:9: warning: unused variable 'ans' [-Wunused-variable]
   42 |     int ans = -1;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Number of queries: 4
2 Correct 2 ms 2640 KB Number of queries: 4
3 Correct 2 ms 2640 KB Number of queries: 4
4 Correct 2 ms 2640 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2640 KB Number of queries: 8
2 Correct 13 ms 2688 KB Number of queries: 9
3 Correct 22 ms 2640 KB Number of queries: 9
4 Correct 16 ms 2700 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2712 KB Number of queries: 9
2 Correct 13 ms 2640 KB Number of queries: 9
3 Correct 19 ms 2672 KB Number of queries: 9
4 Correct 15 ms 2680 KB Number of queries: 9