Submission #61607

# Submission time Handle Problem Language Result Execution time Memory
61607 2018-07-26T08:02:22 Z Flying_dragon_02 Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
5 ms 764 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

vector<int> graph[600];
int child[600], m, root, par[600], ok = 0;
bool vis1[600], vis2[600];
vector<int> ask;

void solve(int u, int p){
    vis2[u] = 1;
    ask.pb(u);
    for(int i = 0; i < graph[u].size(); i++){
        int v = graph[u][i];
        if(v == p) continue;
        solve(v, u);
    }
}

void dfs(int u){
    vis1[u] = 1;
    child[u] = 1;
    for(int i = 0; i < graph[u].size(); i++){
        int v = graph[u][i];
        if(vis2[v] == 0 && vis1[v] == 0){
            dfs(v);
            par[v] = u;
            child[u] += child[v];
        }
    }
    if(child[u] == m / 2 && ok == 0){
        solve(u, par[u]);
        ok = 1;
    }
}

int findEgg(int N, vector<ii> bridges){
	for(int i = 1; i <= N; i++)
	graph[i].clear();
    for(int i = 0; i < bridges.size(); i++){
        int u = bridges[i].fi, v = bridges[i].se;
        graph[u].pb(v); graph[v].pb(u);
    }
    memset(vis2, 0, sizeof(vis2));
    m = N;
    while(m != 1){
        ask.clear();
        ok = 0;
        for(int i = 1; i <= N; i++){
            if(vis2[i] == 0){
                memset(vis1, 0, sizeof(vis1));
                dfs(i);
                if(ask.size() > 0){
                    if(query(ask) == 0){
                        bool vis3[N];
                        memset(vis3, 0, sizeof(vis3));
                        for(int j = 0; j < ask.size(); j++){
                            vis3[ask[j]] = 1;
                            vis2[ask[j]] = 0;
                        }
                        for(int j = 1; j <= N; j++){
                            if(vis3[j] == 0 && vis2[j] == 0)
                                vis2[j] = 1;
                        }
                        break;
                    }
                }
            }
        }
        m -= m / 2;
    }
    ask.clear();
    for(int i = 1; i <= N; i++){
        if(vis2[i] == 0)
            return i;
    }
}

Compilation message

eastereggs.cpp: In function 'void solve(int, int)':
eastereggs.cpp:20:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < graph[u].size(); i++){
                    ~~^~~~~~~~~~~~~~~~~
eastereggs.cpp: In function 'void dfs(int)':
eastereggs.cpp:30:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < graph[u].size(); i++){
                    ~~^~~~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:47:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < bridges.size(); i++){
                    ~~^~~~~~~~~~~~~~~~
eastereggs.cpp:64:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         for(int j = 0; j < ask.size(); j++){
                                        ~~^~~~~~~~~~~~
eastereggs.cpp:84:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 724 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 764 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -