답안 #1109510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1109510 2024-11-07T00:50:51 Z the_coding_pooh Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
23 ms 848 KB
#include <bits/stdc++.h>
// #define LOCAL

#define uwu return

using namespace std;

const int SIZE = 513;

vector <int> graph[SIZE];

#define fs first
#define sc second

#ifdef LOCAL

int findEgg(int N, vector<pair<int, int>> bridges);


int a;

int query(vector <int> vec){
    for(auto i:vec){
        if(i == a)
            return 1;
    }
    return 0;
}

int main(){
    int N;
    cin >> N >> a;
    vector <pair<int, int>> edges;
    for (int i = 1, u, v; i < N; i++){
        cin >> u >> v;
        edges.push_back({u, v});
    }
    int tmp = findEgg(N, edges);
    if(tmp == a)
        cout << "AC\n";
    else{
        cout << "WA\n";
        cout << tmp << '\n';
    }
    uwu 0;
}

#else
int query(vector < int > islands);
#endif

void dfs(vector <int>& vertices, int nd, int rt){
    vertices.push_back(nd);
    for(auto i:graph[nd]){
        if(i != rt)
            dfs(vertices, i, nd);
    }
    return;
}

int findEgg (int N, vector <pair<int, int>> bridges){
    for (auto i:bridges){
        graph[i.fs].clear();
        graph[i.sc].clear();
    }
    for(auto i:bridges){
        graph[i.fs].push_back(i.sc);
        graph[i.sc].push_back(i.fs);
    }
    vector <int> vertices;
    dfs(vertices, 1, 0);
    int L = 0, R = N - 1, M;
    while(L != R){
        vector <int> tmp = vertices;
        M = (L + R) / 2;
        tmp.erase(tmp.begin() + M + 1, tmp.end());
        if(query(tmp))
            R = M;
        else
            L = M + 1;
    }
    uwu vertices[L];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 336 KB Number of queries: 4
2 Correct 2 ms 336 KB Number of queries: 4
3 Correct 2 ms 336 KB Number of queries: 4
4 Correct 2 ms 336 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 492 KB Number of queries: 8
2 Correct 12 ms 496 KB Number of queries: 9
3 Correct 23 ms 336 KB Number of queries: 9
4 Correct 14 ms 592 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 336 KB Number of queries: 9
2 Correct 12 ms 504 KB Number of queries: 9
3 Correct 16 ms 848 KB Number of queries: 9
4 Correct 15 ms 492 KB Number of queries: 9