답안 #918255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918255 2024-01-29T13:51:34 Z TahirAliyev Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
25 ms 5680 KB
#include <bits/stdc++.h>
#include "grader.h"
#define ll int
#define vl vector<ll>
#define fi first
#define se second
#define pb push_back
 
using namespace std;
const int sz = 2e5+5;
vl adj[sz];
vl et;
void dfs(ll node, ll p){
    et.pb(node);
    for(auto edge: adj[node]){
        if(edge == p){continue;}
        dfs(edge, node);
    }
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
    ll i, j;
    for(i=0;i<sz;i++){
        adj[i].clear();
    }
    et.clear();
    for(i=0;i<bridges.size();i++){
        adj[bridges[i].fi].push_back(bridges[i].se);
        adj[bridges[i].se].push_back(bridges[i].fi);
    }
    dfs(1, 0);
    ll lo = 0, hi = N-1, mid, best = 0;
    while(lo < hi){
        mid = (lo + hi) >> 1;
        vl t;
        for(i = 0; i<=mid; i++){
            t.pb(et[i]);
        }
        if(query(t)){
            hi = mid;
        }   
        else{
            lo = mid + 1;
        }
    }
    return et[lo];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:27:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(i=0;i<bridges.size();i++){
      |             ~^~~~~~~~~~~~~~~
eastereggs.cpp:22:11: warning: unused variable 'j' [-Wunused-variable]
   22 |     ll i, j;
      |           ^
eastereggs.cpp:32:31: warning: unused variable 'best' [-Wunused-variable]
   32 |     ll lo = 0, hi = N-1, mid, best = 0;
      |                               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4952 KB Number of queries: 4
2 Correct 4 ms 4952 KB Number of queries: 4
3 Correct 4 ms 4952 KB Number of queries: 4
4 Correct 5 ms 4952 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5416 KB Number of queries: 8
2 Correct 16 ms 5432 KB Number of queries: 9
3 Correct 18 ms 5156 KB Number of queries: 9
4 Correct 21 ms 5428 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 5444 KB Number of queries: 9
2 Correct 25 ms 5680 KB Number of queries: 9
3 Correct 22 ms 5428 KB Number of queries: 9
4 Correct 20 ms 5664 KB Number of queries: 9