답안 #952166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952166 2024-03-23T08:11:45 Z vjudge1 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
컴파일 오류
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()
{
	freopen("t.in","r",stdin);
	freopen("t.out","w",stdout);
	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 main()':
garden.cpp:43:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  freopen("t.in","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~
garden.cpp:44:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  freopen("t.out","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cczoAgAe.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc2WVL3h.o:garden.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cczoAgAe.o: in function `main':
grader.cpp:(.text.startup+0x3f): undefined reference to `count_routes(int, int, int, int (*) [2], int, int*)'
collect2: error: ld returned 1 exit status