QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569344#9319. Bull FarmLinkZeldaRE 0ms0kbC++142.2kb2024-09-16 22:15:332024-09-16 22:15:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-16 22:15:33]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-16 22:15:33]
  • 提交

answer

#include<bits/stdc++.h>
#define pr pair<int,int>

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int N=2005,M=20*N;
int n,l,q;
int head[N],to[M],nxt[M],w[M],cnt;
void add(int u,int v,int ww)
{
	to[++cnt]=v;
	nxt[cnt]=head[u];
	head[u]=cnt;
	w[cnt]=ww;
}

char s[N*2];
int t[N],sum[N],bin[N];
int anc(int x){return x==bin[x]?x:bin[x]=anc(bin[x]);}
queue<int>Q[N];
bool vis[N];
int ans[N][N],dis[N];

void solve()
{
	n=read(),l=read(),q=read();
	fill(head,head+n+1,0);cnt=0;
	for(int i=1;i<=n;i++)
		bin[i]=i;
	for(int i=1;i<=l;i++)
	{
		scanf("%s",s+1);
		for(int j=1;j<=n;j++)
			t[j]=(s[2*j-1]-48)*50+(s[2*j]-48);
		fill(sum,sum+n+1,0);
		for(int j=1;j<=n;j++)
			sum[t[j]]++;
		int summ=0;
		for(int j=1;j<=n;j++)
			summ+=(sum[j]==1);
		if(summ<n-2)
			continue;
		if(summ==n)
		{
			for(int j=1;j<=n;j++)
			{
				int x=j,y=t[j];
				if(anc(x)==anc(y))
					continue;
				bin[anc(x)]=anc(y);
				add(x,y,i);
				add(y,x,i);
			}
		}
		else
		{
			int x=0,y=0,qwq=0;
			for(int j=1;j<=n;j++)
			{
				if(sum[j]==0)
					qwq=j;
				if(sum[t[j]]==2)
				{
					if(!x)
						x=j;
					else
						y=j;
				}
			}
			if(x!=qwq)
				add(x,qwq,i);
			if(y!=qwq)
				add(y,qwq,i);
		}
	}
	for(int i=1;i<=n;i++)
	{
		fill(vis,vis+n+1,0);
		fill(dis,dis+n+1,1e9);
		dis[i]=0;
		Q[0].push(i);
		for(int j=0;j<=l;j++)
		{
			while(!Q[j].empty())
			{
				int now=Q[j].front();Q[j].pop();
				if(vis[now])
					continue;
				vis[now]=1;
				for(int k=head[now];k;k=nxt[k])
				{
					int v=to[k];
					if(dis[v]>max(dis[now],w[k]))
					{
						dis[v]=max(dis[now],w[k]);
						Q[dis[v]].push(v);
					}
				}
			}
		}
		for(int j=1;j<=n;j++)
			ans[i][j]=dis[j];
	}
	while(q--)
	{
		scanf("%s",s+1);
		int a=(s[1]-48)*50+(s[2]-48);
		int b=(s[3]-48)*50+(s[4]-48);
		int c=(s[5]-48)*50+(s[6]-48);
		putchar(ans[a][b]>c?'0':'1');
	}
	puts("");
} 

signed main()
{
	freopen("1.out","w",stdout);
	int Tests=read();
	while(Tests--)
		solve();
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:


result: