답안 #723988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723988 2023-04-14T14:57:49 Z stevancv Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
23 ms 368 KB
#include <bits/stdc++.h>
#include "grader.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 600 + 2;
const int inf = 1e9;
vector<int> g[N], order;
void Dfs(int s, int e) {
    order.push_back(s);
    for (int u : g[s]) {
        if (u != e) Dfs(u, s);
    }
}
int findEgg(int n, vector<pair<int, int>> e) {
    order.clear();
    for (int i = 1; i <= n; i++) g[i].clear();
    for (auto u : e) {
        g[u.first].push_back(u.second);
        g[u.second].push_back(u.first);
    }
    Dfs(1, 0);
    int l = 0, r = n - 1;
    while (l < r) {
        int mid = l + r >> 1;
        vector<int> t;
        for (int i = 0; i <= mid; i++) t.push_back(order[i]);
        if (query(t)) r = mid;
        else l = mid + 1;
    }
    return order[r];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:29:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |         int mid = l + r >> 1;
      |                   ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Correct 1 ms 208 KB Number of queries: 4
3 Correct 1 ms 208 KB Number of queries: 4
4 Correct 1 ms 216 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 352 KB Number of queries: 8
2 Correct 16 ms 348 KB Number of queries: 9
3 Correct 20 ms 356 KB Number of queries: 9
4 Correct 20 ms 360 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 368 KB Number of queries: 9
2 Correct 13 ms 336 KB Number of queries: 9
3 Correct 13 ms 356 KB Number of queries: 9
4 Correct 16 ms 360 KB Number of queries: 9