답안 #486329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486329 2021-11-11T09:41:40 Z NintsiChkhaidze Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
400 ms 460 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];
priority_queue <pair<int,int> > pq;

void dfs(int x,int par){
    for  (int j=0;j<v[x].size();j++){
        int to = v[x][j];
        if (to == par) continue;
        dp[to] = dp[x] + 1;
        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;
}
int go(int n, vector < pair < int, int > > vec,vector <int> vert){
  if (vert.size() == 1) return vert[0];
    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);
    }
   
    dp[vert[0]] = 1,mx = 1,l = vert[0];
    dfs(vert[0],vert[0]);
     
    vector <int> q; q.clear();
    pq.push({mx,l});
    while(q.size() < (n + 1)/2){
        int x = pq.top().second;
        pq.pop();
        f[x] = 1,q.pb(x);
        for (int j = v[x].size() - 1; j>=0; j--){
            int to = v[x][j];
            if (!f[to]) {pq.push({dp[to],to}); break;}
        }
    }
  
   if (query(q) == 1){
       int m=0,raod=0;
       vector <pair<int,int> > edges; edges.clear();
       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});
       }
       vector <int> newv; newv.clear();
       for (int i = 0; i < vert.size(); i++)
          if (f[vert[i]]) newv.pb(vert[i]);

       clear(n);
       return go(newv.size(), edges, newv);
   }
   else{
       vector <pair<int,int> > edges; edges.clear();
       int m = 0,raod=0;
       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});
       }
       vector <int> newv; newv.clear();
       for (int i = 0; i < vert.size(); i++)
          if (!f[vert[i]]) newv.pb(vert[i]);
        
       clear(n);
       return go(newv.size(), edges, newv);
   }
    return -1;
}

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

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for  (int j=0;j<v[x].size();j++){
      |                   ~^~~~~~~~~~~~
eastereggs.cpp: In function 'int go(int, std::vector<std::pair<int, int> >, std::vector<int>)':
eastereggs.cpp:39:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |     while(q.size() < (n + 1)/2){
      |           ~~~~~~~~~^~~~~~~~~~~
eastereggs.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |        for (int i=0;i<vec.size();i++){
      |                     ~^~~~~~~~~~~
eastereggs.cpp:57:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |        for (int i = 0; i < vert.size(); i++)
      |                        ~~^~~~~~~~~~~~~
eastereggs.cpp:50:12: warning: unused variable 'm' [-Wunused-variable]
   50 |        int m=0,raod=0;
      |            ^
eastereggs.cpp:50:16: warning: unused variable 'raod' [-Wunused-variable]
   50 |        int m=0,raod=0;
      |                ^~~~
eastereggs.cpp:66:22: 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:26: 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++)
      |                        ~~^~~~~~~~~~~~~
eastereggs.cpp:65:12: warning: unused variable 'm' [-Wunused-variable]
   65 |        int m = 0,raod=0;
      |            ^
eastereggs.cpp:65:18: warning: unused variable 'raod' [-Wunused-variable]
   65 |        int m = 0,raod=0;
      |                  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 456 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1377 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3025 ms 328 KB Time limit exceeded
2 Halted 0 ms 0 KB -