#include "park.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1405;
const int M=3050;
static int pl[1400];
int use[N],n;
int query(int u, int v)
{
if(u>v) swap(u,v);
for(int i=0;i<n;i++) pl[i]=use[i];
return Ask(u,v,pl);
}
int fir[N],nxt[M],tot,nod[M];
void Add(int u, int v){ tot++;nxt[tot]=fir[u];fir[u]=tot;nod[tot]=v;}
void AddEdge(int u, int v)
{
if(u>v) swap(u,v);
Answer(u,v);
Add(u,v);
Add(v,u);
}
int col[N];
int all(int x, int y)
{
for(int i=0;i<n;i++) use[i]=col[i]==1;
use[x]=use[y]=1;
return query(x,y);
}
int Get(int x, int y)
{
int top=n-1,bot=0,mid,ans;
while(top>=bot)
{
mid=top+bot>>1;
for(int i=0;i<=mid;i++) use[i]=col[i]!=2;
for(int i=mid+1;i<n;i++) use[i]=col[i]==1;
use[x]=use[y]=1;
if(query(x,y)) ans=mid,top=mid-1;
else bot=mid+1;
}
return ans;
}
int was[N];
void Del(int y)
{
was[y]=0;
for(int i=fir[y];i;i=nxt[i]) if(was[nod[i]]) Del(nod[i]);
}
int in[N];
vector<int> nodes;
void DFS(int y)
{
nodes.push_back(y);in[y]=1;
for(int i=fir[y];i;i=nxt[i]) if(!in[nod[i]] && was[nod[i]]) DFS(nod[i]);
}
void Edge(int x)
{
for(int i=0;i<n;i++) was[i]=col[i]==1;
for(int y=0;y<n;y++)
{
if(!was[y]) continue;
for(int i=0;i<n;i++) use[i]=was[i];
use[x]=use[y]=1;
if(!query(x,y)){ Del(y);continue;}
for(int i=0;i<n;i++) in[i]=0;
nodes.clear();
DFS(y);
int top=(int)nodes.size()-1,bot=0,mid,ans;
while(top>=bot)
{
mid=top+bot>>1;
for(int i=0;i<n;i++) use[i]=0;
for(int i=0;i<=mid;i++) use[nodes[i]]=1;
use[x]=use[y]=1;
if(query(x,y)) ans=nodes[mid],top=mid-1;
else bot=mid+1;
}
AddEdge(x,ans);
was[ans]=0;
y--;
}
}
void Work(int x)
{
col[x]=2;
while(!all(0,x)) Work(Get(0,x));
Edge(x);
col[x]=1;
}
void Detect(int T, int N)
{
n=N;col[0]=1;
for(int i=1;i<n;i++) if(!col[i]) Work(i);
}
Compilation message
park.cpp: In function 'int Get(int, int)':
park.cpp:35:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid=top+bot>>1;
~~~^~~~
park.cpp: In function 'void Edge(int)':
park.cpp:72:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
mid=top+bot>>1;
~~~^~~~
park.cpp: In function 'int Get(int, int)':
park.cpp:42:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
return ans;
^~~
park.cpp: In function 'void Edge(int)':
park.cpp:80:11: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
was[ans]=0;
~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
384 KB |
Output is correct |
3 |
Correct |
9 ms |
384 KB |
Output is correct |
4 |
Correct |
22 ms |
512 KB |
Output is correct |
5 |
Correct |
47 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
429 ms |
632 KB |
Output is correct |
2 |
Correct |
157 ms |
632 KB |
Output is correct |
3 |
Correct |
222 ms |
684 KB |
Output is correct |
4 |
Correct |
445 ms |
632 KB |
Output is correct |
5 |
Correct |
428 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
536 KB |
Output is correct |
2 |
Correct |
253 ms |
656 KB |
Output is correct |
3 |
Correct |
229 ms |
512 KB |
Output is correct |
4 |
Correct |
200 ms |
540 KB |
Output is correct |
5 |
Correct |
267 ms |
640 KB |
Output is correct |
6 |
Correct |
216 ms |
532 KB |
Output is correct |
7 |
Correct |
261 ms |
512 KB |
Output is correct |
8 |
Correct |
248 ms |
644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
536 KB |
Output is correct |
2 |
Correct |
266 ms |
512 KB |
Output is correct |
3 |
Correct |
267 ms |
640 KB |
Output is correct |
4 |
Correct |
319 ms |
632 KB |
Output is correct |
5 |
Correct |
253 ms |
656 KB |
Output is correct |
6 |
Correct |
262 ms |
632 KB |
Output is correct |
7 |
Correct |
327 ms |
632 KB |
Output is correct |
8 |
Correct |
256 ms |
632 KB |
Output is correct |
9 |
Correct |
270 ms |
512 KB |
Output is correct |
10 |
Correct |
304 ms |
632 KB |
Output is correct |
11 |
Correct |
289 ms |
652 KB |
Output is correct |
12 |
Correct |
269 ms |
640 KB |
Output is correct |
13 |
Correct |
305 ms |
632 KB |
Output is correct |
14 |
Correct |
266 ms |
636 KB |
Output is correct |
15 |
Correct |
289 ms |
512 KB |
Output is correct |
16 |
Correct |
301 ms |
632 KB |
Output is correct |
17 |
Correct |
408 ms |
632 KB |
Output is correct |
18 |
Correct |
269 ms |
632 KB |
Output is correct |
19 |
Correct |
314 ms |
652 KB |
Output is correct |
20 |
Correct |
281 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
345 ms |
692 KB |
Output is correct |
2 |
Correct |
306 ms |
760 KB |
Output is correct |
3 |
Correct |
365 ms |
624 KB |
Output is correct |
4 |
Correct |
341 ms |
568 KB |
Output is correct |
5 |
Correct |
328 ms |
512 KB |
Output is correct |
6 |
Correct |
349 ms |
512 KB |
Output is correct |
7 |
Correct |
296 ms |
512 KB |
Output is correct |
8 |
Correct |
313 ms |
632 KB |
Output is correct |
9 |
Correct |
274 ms |
512 KB |
Output is correct |
10 |
Correct |
279 ms |
512 KB |
Output is correct |
11 |
Correct |
285 ms |
660 KB |
Output is correct |
12 |
Correct |
296 ms |
632 KB |
Output is correct |
13 |
Correct |
234 ms |
616 KB |
Output is correct |
14 |
Correct |
321 ms |
512 KB |
Output is correct |
15 |
Correct |
308 ms |
632 KB |
Output is correct |
16 |
Correct |
233 ms |
512 KB |
Output is correct |
17 |
Correct |
380 ms |
632 KB |
Output is correct |
18 |
Correct |
284 ms |
512 KB |
Output is correct |