Submission #117151

# Submission time Handle Problem Language Result Execution time Memory
117151 2019-06-15T03:06:37 Z tinjyu Highway Tolls (IOI18_highway) C++14
100 / 100
407 ms 13656 KB
#include "highway.h"
#include <iostream>
using namespace std;
 
long long int sure[130005],tag[90005],tree[900005][2],t[1000005][2],father[900005][2],cnt,road[900005],map[2600005][2],m,p[1300005];
long long int check()
{
	vector<int> w(m);
	for(int i=0;i<m;i++)w[i]=p[i];
	int e=ask(w);
	//cout<<"解"<<e<<endl;
	return e; 
}
void find_pair(int n,vector<int> u,vector<int> v,int a, int b) {
	m=u.size();
	//for(int i=0;i<m;i++)sure[i]=1;
	for(int i=0;i<n;i++)road[i]=-1;
	for(int i=0;i<m;i++)
	{
		int x=u[i],y=v[i];
		map[i*2][0]=x;
		map[i*2][1]=road[y];
		road[y]=i*2;
		map[i*2+1][0]=y;
		map[i*2+1][1]=road[x];
		road[x]=i*2+1;
	}
	cnt=check();
	//cout<<cnt<<endl;
	int point;
	int l=0,r=m-1;
	while(l<r)
	{
		int mid=(l+r)/2;
		for(int i=l;i<=mid;i++)p[i]=1;
		long long int tmp=check();
		if(tmp==cnt)l=mid+1;
		else 
		{
			for(int i=l;i<=mid;i++)p[i]=0;
			r=mid;
		}
	}
	point=l;
	//cout<<point<<endl;
	long long int start=u[point];
	long long int end=v[point];
	int tp=1,tpp=2;
	t[1][0]=start;
	t[1][1]=0;
	t[2][0]=end;
	t[2][1]=1;
	tree[0][0]++;
	tree[0][1]++;
	tree[1][0]=start;
	tree[1][1]=end;
	tag[start]=1;
	tag[end]=1;
	for(int i=0;i<n;i++)father[i][0]=-2;
	//cout<<start<<" "<<end<<" "<<point<<endl;
	father[start][0]=end;
	father[start][1]=point;
	father[end][0]=start;
	father[end][1]=point;
	p[130000]=1;
	while(tp<=tpp)
	{
		int now=t[tp][0];
		int g=road[now];
		while(g!=-1)
		{
			//if(map[g][0]==29918)
			//{
				//cout<<t[tp][0]<<" "<<t[tp][1]<<" "<<map[g][0]<<endl;
			//}
			if(tag[map[g][0]]==0)
			{
				tag[map[g][0]]=1;
				father[map[g][0]][0]=now;
				father[map[g][0]][1]=g/2;
				tpp++;
				t[tpp][0]=map[g][0];
				t[tpp][1]=t[tp][1];
				tree[0][t[tp][1]]++;
				tree[tree[0][t[tp][1]]][t[tp][1]]=map[g][0];
			}
			g=map[g][1];
		}
		//system("pause");
		tp++;
	}
	for(int i=0;i<m;i++)p[i]=0;
	//cout<<endl;
	l=1,r=tree[0][0];
	int startans;
	for(int i=0;i<m;i++)p[i]=0;
	while(l<=r)
	{
		int mid=(l+r)/2;
		//cout<<l<<" "<<r<<endl;
		for(int i=0;i<m;i++)p[i]=1;
		for(int i=1;i<=tree[0][1];i++)
		{
			int g=tree[i][1];
			//cout<<tree[i][1]<<" ";
			while(p[father[g][1]]==1)
			{
				p[father[g][1]]=0;
				g=father[g][0];
			}
		}
		for(int i=l;i<=mid;i++)
		{
			//cout<<tree[i][0]<<" "; 
			int g=tree[i][0];
			//cout<<i<<" "<<tree[i][0]<<"  "; 
			while(p[father[g][1]]==1)
			{
				//cout<<father[g][0]<<" ";
				p[father[g][1]]=0;
				g=father[g][0];
			}
			//cout<<endl;
		}
		//cout<<p[father[30635][1]]<<endl;
		
		
		long long int tmp=check();
		//cout<<tmp<<endl;
		if(tmp==cnt)
		{
			startans=tree[mid][0];
			//cout<<startans<<endl;
			r=mid-1;
		}
		else l=mid+1;
	}
	//cout<<startans<<endl;
	/*while(sure[father[o][1]]==1)
	{
		cout<<father[o][0]<<endl;
		sure[father[o][1]]=0;
		//p[father[o][1]]=0;
		o=father[o][0];
	}*/
	//cout<<"firstend"<<endl;
	//for(int i=0;i<m;i++)cout<<p[i]<<" ";
	//cout<<endl;
	//cout<<cnt<<endl;
	//cout<<endl;
	//for(int i=0;i<m;i++)p[i]=1;
	//cout<<cnt<<endl;
	//cout<<cnt<<endl;
	l=1,r=tree[0][1];
	int endans;
	while(l<=r)
	{
		int mid=(l+r)/2;
		//cout<<"二分"<<l<<" "<<r<<endl;
		for(int i=0;i<m;i++)p[i]=1;
		for(int i=1;i<=tree[0][0];i++)
		{
			int g=tree[i][0];
			//cout<<tree[i][1]<<" ";
			//cout<<"建樹"<<g<<endl;
			while(p[father[g][1]]==1)
			{
				//cout<<g<<" "<<father[g][0]<<"  "; 
				p[father[g][1]]=0;
				g=father[g][0];
			}
			//cout<<endl;
		}
		//cout<<endl;
		for(int i=l;i<=mid;i++)
		{
			//if(tree[i][1]==56305)cout<<i<<endl;
			int g=tree[i][1];
			//cout<<i<<" "<<tree[i][1]<<endl;
			while(p[father[g][1]]==1)
			{
				//cout<<father[g][1]<<" ";
				p[father[g][1]]=0;
				g=father[g][0];
			}
		}
		/*o=56305;
		while(sure[father[o][1]]==1)
		{
			//cout<<father[o][0]<<" "<<p[father[o][1]]<<endl;
			sure[father[o][1]]=0;
			//p[father[o][1]]=0;
			o=father[o][0];
		}*/
		//for(int i=0;i<m;i++)sure[i]=1;
		//cout<<endl;
		long long int tmp=check();
		//cout<<tmp<<endl;
		if(tmp==cnt)
		{
			endans=tree[mid][1];
			//cout<<endans<<endl;
			r=mid-1;
		}
		else l=mid+1;
	}
	//o=endans;
	/*while(sure[father[o][1]]==1)
	{
		//cout<<father[o][0]<<endl;
		sure[father[o][1]]=0;
		//p[father[o][1]]=0;
		o=father[o][0];
	}*/
	//cout<<startans<<" "<<endans<<endl;
	answer(startans,endans);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:216:8: warning: 'endans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  answer(startans,endans);
  ~~~~~~^~~~~~~~~~~~~~~~~
highway.cpp:216:8: warning: 'startans' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 428 KB Output is correct
2 Correct 2 ms 424 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 428 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 380 KB Output is correct
2 Correct 22 ms 1596 KB Output is correct
3 Correct 180 ms 11380 KB Output is correct
4 Correct 221 ms 11312 KB Output is correct
5 Correct 227 ms 11436 KB Output is correct
6 Correct 191 ms 11440 KB Output is correct
7 Correct 193 ms 11308 KB Output is correct
8 Correct 225 ms 11304 KB Output is correct
9 Correct 194 ms 11332 KB Output is correct
10 Correct 231 ms 11320 KB Output is correct
11 Correct 290 ms 10844 KB Output is correct
12 Correct 277 ms 11080 KB Output is correct
13 Correct 279 ms 11276 KB Output is correct
14 Correct 267 ms 11320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1460 KB Output is correct
2 Correct 39 ms 2752 KB Output is correct
3 Correct 55 ms 4044 KB Output is correct
4 Correct 195 ms 10804 KB Output is correct
5 Correct 157 ms 10900 KB Output is correct
6 Correct 184 ms 11048 KB Output is correct
7 Correct 173 ms 11244 KB Output is correct
8 Correct 195 ms 10996 KB Output is correct
9 Correct 168 ms 10956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 34 ms 1416 KB Output is correct
3 Correct 148 ms 8908 KB Output is correct
4 Correct 192 ms 11344 KB Output is correct
5 Correct 192 ms 11420 KB Output is correct
6 Correct 184 ms 11332 KB Output is correct
7 Correct 177 ms 11324 KB Output is correct
8 Correct 187 ms 11320 KB Output is correct
9 Correct 250 ms 11248 KB Output is correct
10 Correct 228 ms 11340 KB Output is correct
11 Correct 280 ms 11416 KB Output is correct
12 Correct 325 ms 11108 KB Output is correct
13 Correct 303 ms 11136 KB Output is correct
14 Correct 267 ms 10824 KB Output is correct
15 Correct 179 ms 11420 KB Output is correct
16 Correct 166 ms 11356 KB Output is correct
17 Correct 247 ms 11196 KB Output is correct
18 Correct 264 ms 11336 KB Output is correct
19 Correct 182 ms 11324 KB Output is correct
20 Correct 211 ms 11224 KB Output is correct
21 Correct 166 ms 11348 KB Output is correct
22 Correct 168 ms 11328 KB Output is correct
23 Correct 233 ms 10636 KB Output is correct
24 Correct 266 ms 10736 KB Output is correct
25 Correct 297 ms 11188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1532 KB Output is correct
2 Correct 25 ms 1588 KB Output is correct
3 Correct 279 ms 11944 KB Output is correct
4 Correct 307 ms 12220 KB Output is correct
5 Correct 346 ms 13444 KB Output is correct
6 Correct 352 ms 13268 KB Output is correct
7 Correct 362 ms 13060 KB Output is correct
8 Correct 348 ms 13092 KB Output is correct
9 Correct 245 ms 10080 KB Output is correct
10 Correct 226 ms 9684 KB Output is correct
11 Correct 234 ms 10772 KB Output is correct
12 Correct 349 ms 11952 KB Output is correct
13 Correct 339 ms 12524 KB Output is correct
14 Correct 354 ms 13048 KB Output is correct
15 Correct 337 ms 13468 KB Output is correct
16 Correct 272 ms 10428 KB Output is correct
17 Correct 214 ms 11240 KB Output is correct
18 Correct 235 ms 11428 KB Output is correct
19 Correct 233 ms 11360 KB Output is correct
20 Correct 228 ms 11384 KB Output is correct
21 Correct 353 ms 13548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1576 KB Output is correct
2 Correct 20 ms 1592 KB Output is correct
3 Correct 315 ms 11340 KB Output is correct
4 Correct 308 ms 11656 KB Output is correct
5 Correct 321 ms 12072 KB Output is correct
6 Correct 358 ms 13272 KB Output is correct
7 Correct 213 ms 12012 KB Output is correct
8 Correct 270 ms 12072 KB Output is correct
9 Correct 313 ms 12068 KB Output is correct
10 Correct 368 ms 12996 KB Output is correct
11 Correct 368 ms 13152 KB Output is correct
12 Correct 333 ms 13332 KB Output is correct
13 Correct 232 ms 10776 KB Output is correct
14 Correct 252 ms 9696 KB Output is correct
15 Correct 251 ms 10768 KB Output is correct
16 Correct 264 ms 9680 KB Output is correct
17 Correct 236 ms 10760 KB Output is correct
18 Correct 235 ms 9660 KB Output is correct
19 Correct 307 ms 12068 KB Output is correct
20 Correct 313 ms 12900 KB Output is correct
21 Correct 336 ms 13096 KB Output is correct
22 Correct 391 ms 13024 KB Output is correct
23 Correct 342 ms 13100 KB Output is correct
24 Correct 337 ms 13140 KB Output is correct
25 Correct 338 ms 13384 KB Output is correct
26 Correct 299 ms 13416 KB Output is correct
27 Correct 226 ms 11404 KB Output is correct
28 Correct 227 ms 11344 KB Output is correct
29 Correct 179 ms 11488 KB Output is correct
30 Correct 186 ms 11480 KB Output is correct
31 Correct 221 ms 11360 KB Output is correct
32 Correct 258 ms 11336 KB Output is correct
33 Correct 233 ms 11412 KB Output is correct
34 Correct 219 ms 11356 KB Output is correct
35 Correct 240 ms 11288 KB Output is correct
36 Correct 233 ms 11416 KB Output is correct
37 Correct 267 ms 11496 KB Output is correct
38 Correct 164 ms 11628 KB Output is correct
39 Correct 359 ms 13496 KB Output is correct
40 Correct 352 ms 13488 KB Output is correct
41 Correct 337 ms 13656 KB Output is correct
42 Correct 407 ms 13280 KB Output is correct