Submission #153522

# Submission time Handle Problem Language Result Execution time Memory
153522 2019-09-14T12:28:06 Z nicolaalexandra Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
9 ms 504 KB
#include <iostream>
#include "grader.h"
#include <vector>
#include <algorithm>
#define DIM 530
using namespace std;
vector <int> E,v,L[DIM];
int n,i,x,y;
vector <pair<int,int> > mch;
/*int query (vector <int> v){
    for (int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
    cout<<endl;
    int ans;
    cin>>ans;
    return ans;
}*/

void dfs (int nod, int tata){
    E.push_back(nod);
    for (int i=0;i<L[nod].size();i++){
        int vecin = L[nod][i];
        if (vecin != tata)
            dfs (vecin,nod);
    }
    E.push_back(nod);
}
int verif (int poz1, int poz2){
    v.clear();
    for (int i=poz1;i<=poz2;i++)
        v.push_back(E[i]);
    sort (v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    return query (v);
}
int findEgg (int n, vector <pair<int,int> > mch){
    for (int i=1;i<=n;i++)
        L[i].clear();
    for (int i=0;i<n-1;i++){
        int x = mch[i].first, y = mch[i].second;
        L[x].push_back(y);
        L[y].push_back(x);
    }
    E.clear();
    dfs (1,0);
    int st = 0, dr = E.size()-1;
    while (st < dr){
        int mid = (st+dr)>>1;
        if (verif (st,mid))
            dr = mid;
        else{
            if (verif (mid+1,dr))
                st = mid+1;
        }}
    return E[st];
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<L[nod].size();i++){
                  ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 456 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 504 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 9 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -