Submission #259926

#TimeUsernameProblemLanguageResultExecution timeMemory
259926medkHighway Tolls (IOI18_highway)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "highway.h"

#define ll long long
#define pb push_back
#define x first
#define y second
#define sz(u) (int)(u.size())
#define all(u) u.begin(),u.end()

using namespace std;

vector<vector<pair<int,int>>> g;
vector<bool> blocked;
vector<int> sz, toask, edges;
vector<pair<int,int>> cand;
int n,m;
ll norm,a,b,dist;
int fst,scd;

void calc_sz(int u, int par=-1){
	sz[u]=1;
	for(auto p:g[u]){
		if(p.x==par || blocked[p.x]) continue;
		calc_sz(p.x,u);
		sz[u]+=sz[p.x];
	}
}

int find_centroid(int u, int par, int comp){
	for(auto p:g[u]){
		if(p.x==par || blocked[p.x]) continue;
		if(sz[p.x]>=comp/2) return find_centroid(p.x,u,comp);
	}
	return u;
}

void color(int u, int par){
	for(auto p:g[u]){
		if(p.x==par || blocked[p.x]) continue;
		toask[p.y]=1;
		edges.pb(p.y);
		color(p.x,u);
	}
}

void uncolor(){
	for(int e:edges) toask[e]=0;
	edges.clear();
}

void atdist(int u, int par, int goald, int d=0){
	for(auto p:g[u]){
		if(p.x==par || blocked[p.x]) continue;
		if(d==goald-1){
			cand.pb(p);
		}
		else atdist(p.x,u,goald,d+1);
	}
}

void find_first(int u){
	calc_sz(u);
	int centroid=find_centroid(u,u,sz[u]);
	vector<pair<int,int>> adj;
	for(auto p:g[centroid]){
		if(blocked[p.x]) continue;
		adj.pb(p);
		edges.pb(p.y);
		toask[p.y]=1;
	}
	uncolor();
	int l=0, r=sz(adj)-1;
	if(ask(toask)==norm){
		while(l<r){
			int md=(l+r)/2;
			for(int i=l;i<=md;i++){
				color(adj[i].x);
			}
			if(ask(toask)==norm) l=md+1;
			else r=md;
			uncolor();
		}
		blocked[centroid]=1;
		find_first(adj[l].x);
		return;
	}
	while(l<r){
		int md=(l+r)/2;
		for(int i=l;i<=md;i++){
			toask[adj[i].y]=1;
			edges.pb(adj[i].y);
		}
		if(ask(toask)==norm) l=md+1;
		else r=md;
		uncolor();
	}
	color(adj[i].x);
	ll get=ask(toask);
	uncolor();
	ll dst=(get-norm)/(b-a)+1LL;
	atdist(centroid,-1,dst);
	int l=0, r=sz(cand);
	while(l<r){
		int md=(l+r)/2;
		for(int i=l;i<=md;i++){
			toask[cand[i].y]=1;
			edges.pb(cand[i].y);
		}
		if(ask(toask)==norm) l=md+1;
		else r=md;
		uncolor();
	}
	fst=cand[l].x;
}

void find_second(){
	for(int i=0;i<n;i++) blocked[i]=0;
	cand.clear();
	atdist(fst,-1,dist);
	int l=0, r=sz(cand);
	while(l<r){
		int md=(l+r)/2;
		for(int i=l;i<=md;i++){
			toask[cand[i].y]=1;
			edges.pb(cand[i].y);
		}
		if(ask(toask)==norm) l=md+1;
		else r=md;
		uncolor();
	}
	scd=cand[l].x;
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B){
	n=N, m=sz(U), a=A, b=B;
	g.resize(n), blocked.resize(n), sz.resize(n), toask.resize(m);
	for(int i=0;i<m;i++){
		g[U[i]].pb({V[i],i});
		g[V[i]].pb({U[i],i});
		toask[i]=0;
	}
	norm=ask(toask);
	dist=norm/a;
	find_first(0);
	find_second();
	answer(fst,scd);
}

Compilation message (stderr)

highway.cpp: In function 'void find_first(int)':
highway.cpp:74:17: error: reference to 'norm' is ambiguous
  if(ask(toask)==norm){
                 ^~~~
highway.cpp:18:4: note: candidates are: long long int norm
 ll norm,a,b,dist;
    ^~~~
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from highway.cpp:1:
/usr/include/c++/7/complex:1851:5: note:                 template<class _Tp> typename __gnu_cxx::__promote<_Tp>::__type std::norm(_Tp)
     norm(_Tp __x)
     ^~~~
/usr/include/c++/7/complex:663:5: note:                 template<class _Tp> _Tp std::norm(const std::complex<_Tp>&)
     norm(const complex<_Tp>& __z)
     ^~~~
highway.cpp:78:19: error: too few arguments to function 'void color(int, int)'
     color(adj[i].x);
                   ^
highway.cpp:38:6: note: declared here
 void color(int u, int par){
      ^~~~~
highway.cpp:80:19: error: reference to 'norm' is ambiguous
    if(ask(toask)==norm) l=md+1;
                   ^~~~
highway.cpp:18:4: note: candidates are: long long int norm
 ll norm,a,b,dist;
    ^~~~
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from highway.cpp:1:
/usr/include/c++/7/complex:1851:5: note:                 template<class _Tp> typename __gnu_cxx::__promote<_Tp>::__type std::norm(_Tp)
     norm(_Tp __x)
     ^~~~
/usr/include/c++/7/complex:663:5: note:                 template<class _Tp> _Tp std::norm(const std::complex<_Tp>&)
     norm(const complex<_Tp>& __z)
     ^~~~
highway.cpp:94:18: error: reference to 'norm' is ambiguous
   if(ask(toask)==norm) l=md+1;
                  ^~~~
highway.cpp:18:4: note: candidates are: long long int norm
 ll norm,a,b,dist;
    ^~~~
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from highway.cpp:1:
/usr/include/c++/7/complex:1851:5: note:                 template<class _Tp> typename __gnu_cxx::__promote<_Tp>::__type std::norm(_Tp)
     norm(_Tp __x)
     ^~~~
/usr/include/c++/7/complex:663:5: note:                 template<class _Tp> _Tp std::norm(const std::complex<_Tp>&)
     norm(const complex<_Tp>& __z)
     ^~~~
highway.cpp:98:12: error: 'i' was not declared in this scope
  color(adj[i].x);
            ^
highway.cpp:101:14: error: reference to 'norm' is ambiguous
  ll dst=(get-norm)/(b-a)+1LL;
              ^~~~
highway.cpp:18:4: note: candidates are: long long int norm
 ll norm,a,b,dist;
    ^~~~
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from highway.cpp:1:
/usr/include/c++/7/complex:1851:5: note:                 template<class _Tp> typename __gnu_cxx::__promote<_Tp>::__type std::norm(_Tp)
     norm(_Tp __x)
     ^~~~
/usr/include/c++/7/complex:663:5: note:                 template<class _Tp> _Tp std::norm(const std::complex<_Tp>&)
     norm(const complex<_Tp>& __z)
     ^~~~
highway.cpp:103:6: error: redeclaration of 'int l'
  int l=0, r=sz(cand);
      ^
highway.cpp:73:6: note: 'int l' previously declared here
  int l=0, r=sz(adj)-1;
      ^
highway.cpp:103:11: error: redeclaration of 'int r'
  int l=0, r=sz(cand);
           ^
highway.cpp:73:11: note: 'int r' previously declared here
  int l=0, r=sz(adj)-1;
           ^
highway.cpp:110:18: error: reference to 'norm' is ambiguous
   if(ask(toask)==norm) l=md+1;
                  ^~~~
highway.cpp:18:4: note: candidates are: long long int norm
 ll norm,a,b,dist;
    ^~~~
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from highway.cpp:1:
/usr/include/c++/7/complex:1851:5: note:                 template<class _Tp> typename __gnu_cxx::__promote<_Tp>::__type std::norm(_Tp)
     norm(_Tp __x)
     ^~~~
/usr/include/c++/7/complex:663:5: note:                 template<class _Tp> _Tp std::norm(const std::complex<_Tp>&)
     norm(const complex<_Tp>& __z)
     ^~~~
highway.cpp: In function 'void find_second()':
highway.cpp:128:18: error: reference to 'norm' is ambiguous
   if(ask(toask)==norm) l=md+1;
                  ^~~~
highway.cpp:18:4: note: candidates are: long long int norm
 ll norm,a,b,dist;
    ^~~~
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from highway.cpp:1:
/usr/include/c++/7/complex:1851:5: note:                 template<class _Tp> typename __gnu_cxx::__promote<_Tp>::__type std::norm(_Tp)
     norm(_Tp __x)
     ^~~~
/usr/include/c++/7/complex:663:5: note:                 template<class _Tp> _Tp std::norm(const std::complex<_Tp>&)
     norm(const complex<_Tp>& __z)
     ^~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:143:2: error: reference to 'norm' is ambiguous
  norm=ask(toask);
  ^~~~
highway.cpp:18:4: note: candidates are: long long int norm
 ll norm,a,b,dist;
    ^~~~
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from highway.cpp:1:
/usr/include/c++/7/complex:1851:5: note:                 template<class _Tp> typename __gnu_cxx::__promote<_Tp>::__type std::norm(_Tp)
     norm(_Tp __x)
     ^~~~
/usr/include/c++/7/complex:663:5: note:                 template<class _Tp> _Tp std::norm(const std::complex<_Tp>&)
     norm(const complex<_Tp>& __z)
     ^~~~
highway.cpp:144:7: error: reference to 'norm' is ambiguous
  dist=norm/a;
       ^~~~
highway.cpp:18:4: note: candidates are: long long int norm
 ll norm,a,b,dist;
    ^~~~
In file included from /usr/include/c++/7/ccomplex:39:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from highway.cpp:1:
/usr/include/c++/7/complex:1851:5: note:                 template<class _Tp> typename __gnu_cxx::__promote<_Tp>::__type std::norm(_Tp)
     norm(_Tp __x)
     ^~~~
/usr/include/c++/7/complex:663:5: note:                 template<class _Tp> _Tp std::norm(const std::complex<_Tp>&)
     norm(const complex<_Tp>& __z)
     ^~~~