Submission #952167

# Submission time Handle Problem Language Result Execution time Memory
952167 2024-03-23T08:13:15 Z vjudge1 Tropical Garden (IOI11_garden) C++17
Compilation error
0 ms 0 KB
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
 
inline char nc()
{
	static char buf[100000],*p1=buf,*p2=buf;
	if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
	return *p1++;
}
 
inline void read(int &x){
	char c=nc(),b=1;
	for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
	for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
int N,M,P,Q;
int G[2005];
int R[150005][2];
int size[150005];
int f1[150005],f2[150005];
int F1[150005][35],F2[150005][35];
int Enf1[150005][35],Enf2[150005][35];
int tot;
 
inline int Query(int s,int K){
	int flag=0;
	for (int k=30;k>=0;k--)
		if (K&(1<<k))
		{
			if (!flag || size[s]==1)
				flag=Enf1[s][k],s=F1[s][k];
			else
				flag=Enf2[s][k],s=F2[s][k];
		}
	return s;
}
 
int main()
{
	read(N); read(M); read(P); P++;
	for (int i=1;i<=M;i++)
		read(R[i][0]),read(R[i][1]),R[i][0]++,R[i][1]++;
	for (int i=1;i<=M;i++)
	{
		int u=R[i][0],v=R[i][1];
		size[u]++; size[v]++;
		if (!f1[u]) f1[u]=v; else if (!f2[u]) f2[u]=v;
		if (!f1[v]) f1[v]=u; else if (!f2[v]) f2[v]=u;
	}
	for (int i=1;i<=N;i++)
	{
		F1[i][0]=f1[i]; if (f1[f1[i]]==i) Enf1[i][0]=1;
		F2[i][0]=f2[i]; if (f1[f2[i]]==i) Enf2[i][0]=1;
	}
	for (int k=1;k<=30;k++)
		for (int i=1;i<=N;i++)
		{
			if (Enf1[i][k-1] && size[F1[i][k-1]]!=1)
			{
				F1[i][k]=F2[F1[i][k-1]][k-1];
				Enf1[i][k]=Enf2[F1[i][k-1]][k-1];
			}
			else
			{
				F1[i][k]=F1[F1[i][k-1]][k-1];
				Enf1[i][k]=Enf1[F1[i][k-1]][k-1];
			}
			if (Enf2[i][k-1] && size[F2[i][k-1]]!=1)
			{
				F2[i][k]=F2[F2[i][k-1]][k-1];
				Enf2[i][k]=Enf2[F2[i][k-1]][k-1];
			}
			else
			{
				F2[i][k]=F1[F2[i][k-1]][k-1];
				Enf2[i][k]=Enf1[F2[i][k-1]][k-1];
			}
		}
	read(Q);
	for (int i=1;i<=Q;i++)
		read(G[i]);
	for (int i=1;i<=Q;i++)
	{
		int ans=0;
		for (int j=1;j<=N;j++)
			if (Query(j,G[i])==P)
				ans++;
		printf("%d\n",ans);
	}
	return 0;
}

Compilation message

garden.cpp: In function 'void read(int&)':
garden.cpp:16:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   16 |  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
      |  ^~~
garden.cpp:16:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   16 |  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
      |                                                  ^
garden.cpp: In function 'int Query(int, int)':
garden.cpp:33:17: error: reference to 'size' is ambiguous
   33 |    if (!flag || size[s]==1)
      |                 ^~~~
In file included from /usr/include/c++/10/array:41,
                 from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from garden.cpp:3:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
garden.cpp:22:5: note:                 'int size [150005]'
   22 | int size[150005];
      |     ^~~~
garden.cpp: In function 'int main()':
garden.cpp:49:3: error: reference to 'size' is ambiguous
   49 |   size[u]++; size[v]++;
      |   ^~~~
In file included from /usr/include/c++/10/array:41,
                 from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from garden.cpp:3:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
garden.cpp:22:5: note:                 'int size [150005]'
   22 | int size[150005];
      |     ^~~~
garden.cpp:49:14: error: reference to 'size' is ambiguous
   49 |   size[u]++; size[v]++;
      |              ^~~~
In file included from /usr/include/c++/10/array:41,
                 from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from garden.cpp:3:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
garden.cpp:22:5: note:                 'int size [150005]'
   22 | int size[150005];
      |     ^~~~
garden.cpp:61:24: error: reference to 'size' is ambiguous
   61 |    if (Enf1[i][k-1] && size[F1[i][k-1]]!=1)
      |                        ^~~~
In file included from /usr/include/c++/10/array:41,
                 from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from garden.cpp:3:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
garden.cpp:22:5: note:                 'int size [150005]'
   22 | int size[150005];
      |     ^~~~
garden.cpp:71:24: error: reference to 'size' is ambiguous
   71 |    if (Enf2[i][k-1] && size[F2[i][k-1]]!=1)
      |                        ^~~~
In file included from /usr/include/c++/10/array:41,
                 from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from garden.cpp:3:
/usr/include/c++/10/bits/range_access.h:254:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  254 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:245:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  245 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
garden.cpp:22:5: note:                 'int size [150005]'
   22 | int size[150005];
      |     ^~~~