#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
vector<int> G[600];
vector<int> nodes;
void linearize(int node,int father){
nodes.push_back(node);
for(auto it:G[node]){
if(it != father){
linearize(it,node);
nodes.push_back(node);
}
}
}
vector<int> que;
map< vector<int> , int > Map;
bool done = 0;
bool ok(int le,int ri){
que.clear();
for(int i = le;i <= ri;i++){
que.push_back(nodes[i]);
}
sort(que.begin(),que.end());
que.resize(unique(que.begin(),que.end()) - que.begin());
if(Map.count(que)){
return Map[que];
}
return Map[que] = query(que);
}
int findEgg (int N, vector < pair < int, int > > bridges){
Map.clear();
if(!done){
nodes.clear();
for(int i = 1;i <= N;i++){
G[i].clear();
}
for(auto it:bridges){
G[it.first].push_back(it.second);
G[it.second].push_back(it.first);
}
linearize(1,0);
done = 1;
}
int lo = 0,hi = (int)nodes.size() - 1;
while(hi - lo > 0){
int mid = (lo + hi) / 2;
vector<int> tmp = nodes;
sort(tmp.begin(),tmp.end());
tmp.resize(unique(tmp.begin(),tmp.end()) - tmp.begin());
if(tmp.size() == 1){
nodes = tmp;
break;
}
if(ok(lo,mid)){
hi = mid;
}
else{
lo = mid + 1;
}
}
return nodes[lo];
}
Compilation message
eastereggs.cpp: In function 'bool ok(int, int)':
eastereggs.cpp:35:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
return Map[que] = query(que);
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
Number of queries: 5 |
2 |
Incorrect |
2 ms |
312 KB |
Number of queries: 5 |
3 |
Incorrect |
3 ms |
516 KB |
Number of queries: 5 |
4 |
Incorrect |
2 ms |
516 KB |
Number of queries: 5 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
516 KB |
Number of queries: 9 |
2 |
Incorrect |
20 ms |
516 KB |
Number of queries: 10 |
3 |
Incorrect |
34 ms |
544 KB |
Number of queries: 10 |
4 |
Incorrect |
22 ms |
544 KB |
Number of queries: 10 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
544 KB |
Number of queries: 10 |
2 |
Incorrect |
34 ms |
544 KB |
Number of queries: 10 |
3 |
Incorrect |
38 ms |
544 KB |
Number of queries: 10 |
4 |
Incorrect |
28 ms |
548 KB |
Number of queries: 10 |