답안 #622444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622444 2022-08-04T09:38:49 Z Hanksburger Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
21 ms 464 KB
#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[515], vec, tmp;
void dfs(int x, int p)
{
    vec.push_back(x);
    for (int y:adj[x])
        if (y!=p)
            dfs(y, x);
}
int findEgg(int n, vector<pair<int, int> > edge)
{
    for (int i=1; i<=n; i++)
        adj[i].clear();
    for (int i=0; i<edge.size(); i++)
    {
        int x=edge[i].first, y=edge[i].second;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    vec.clear();
    dfs(1, 1);
    int l=0, r=n-1;
    while (l<r)
    {
        int m=(l+r)/2;
        tmp.clear();
        for (int i=0; i<=m; i++)
            tmp.push_back(vec[i]);
        if (query(tmp))
            r=m;
        else
            l=m+1;
    }
    return vec[l];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i=0; i<edge.size(); i++)
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 6 ms 336 KB Number of queries: 8
2 Correct 11 ms 336 KB Number of queries: 9
3 Correct 21 ms 340 KB Number of queries: 9
4 Correct 17 ms 356 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 368 KB Number of queries: 9
2 Correct 14 ms 352 KB Number of queries: 9
3 Correct 15 ms 464 KB Number of queries: 9
4 Correct 15 ms 348 KB Number of queries: 9