답안 #486339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486339 2021-11-11T10:25:59 Z NintsiChkhaidze Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
10 ms 456 KB
#include <bits/stdc++.h>
#include "grader.h"
#define pb push_back

using namespace std;
vector <int> v[605];
int dp[605],mx,l,f[605],N,ANS;
priority_queue <pair<int,int> > pq;

void dfs(int x,int par){
    dp[x] = dp[par] + 1;
    for (int j=0;j<v[x].size();j++){
        int to = v[x][j];
        if (to == par) continue;
        dfs(to,x);
    }
    if (dp[x] > mx)
        mx = dp[x],l = x;
}

void clear(int n){
    while(pq.size()) pq.pop();
    for (int i = 1; i <= n; i++)
        v[i].clear(),dp[i] = 0,f[i] = 0;
}
void go(int n, vector < pair < int, int > > vec,vector <int> vert){
    if (vert.size() == 1) {
        ANS = vert[0];
        return;
    }
    
    for (int i = 0; i < n - 1; i++){
        int a = vec[i].first,b = vec[i].second;
        v[a].pb(b),v[b].pb(a);
    }
    
    mx = 1,l = vert[0];
    dfs(vert[0],vert[0]);
    
    vector <int> q; q.clear();
    pq.push({mx,l});
    while(pq.size()){
        int x = pq.top().second;
        pq.pop();
        if (f[x] == 1) continue;
        
        f[x] = 1,q.pb(x);
        if (q.size() == n/2) break;
        for (int j = 0; j<v[x].size(); j++){
            int to = v[x][j];
            if (!f[to]) pq.push({dp[to],to});
        }
    }
    
    vector <pair<int,int> > edges; edges.clear();
    vector <int> newv; newv.clear();
    if (query(q) == 1){
        for (int i=0;i<vec.size();i++){
            int a = vec[i].first,b = vec[i].second;
            if (f[a] && f[b]) edges.pb({a,b});
        }
        for (int i = 0; i < vert.size(); i++)
            if (f[vert[i]]) newv.pb(vert[i]);
    }
    else{
        for (int i=0;i<vec.size();i++){
            int a = vec[i].first,b = vec[i].second;
            if (!f[a] && !f[b]) edges.pb({a,b});
        }
        
        for (int i = 0; i < vert.size(); i++)
            if (!f[vert[i]]) newv.pb(vert[i]);
    }
    
    clear(N);
    go(newv.size(), edges, newv);
}

int findEgg (int n, vector < pair < int, int > > vec){
     N = n;
    vector <int> vert; vert.clear();
    for (int i=1;i<=n;i++)
        vert.pb(i);
     go(n,vec,vert);
    clear(N);
    return ANS;
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int j=0;j<v[x].size();j++){
      |                  ~^~~~~~~~~~~~
eastereggs.cpp: In function 'void go(int, std::vector<std::pair<int, int> >, std::vector<int>)':
eastereggs.cpp:48:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |         if (q.size() == n/2) break;
      |             ~~~~~~~~~^~~~~~
eastereggs.cpp:49:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int j = 0; j<v[x].size(); j++){
      |                         ~^~~~~~~~~~~~
eastereggs.cpp:58: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]
   58 |         for (int i=0;i<vec.size();i++){
      |                      ~^~~~~~~~~~~
eastereggs.cpp:62:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int i = 0; i < vert.size(); i++)
      |                         ~~^~~~~~~~~~~~~
eastereggs.cpp:66: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]
   66 |         for (int i=0;i<vec.size();i++){
      |                      ~^~~~~~~~~~~
eastereggs.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for (int i = 0; i < vert.size(); i++)
      |                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Number of queries: 4
2 Runtime error 1 ms 456 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 328 KB Number of queries: 8
2 Runtime error 1 ms 456 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 328 KB Number of queries: 9
2 Runtime error 1 ms 456 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -