QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#590092#9319. Bull Farmrevolutionary_oierWA 1ms9960kbC++144.1kb2024-09-25 21:31:102024-09-25 21:31:11

Judging History

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

  • [2024-09-25 21:31:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9960kb
  • [2024-09-25 21:31:10]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn=2e3+10;
const int maxm=2e6+10;
int t,n,L,q,cnt_,l,tt;
char x[maxn<<2];
int fa[maxn],cnt[2],ct[maxn],dfn[maxn],low[maxn],h[maxn],deg[maxn];
bool in[maxn];
int c[maxn][maxn],head[2][maxn];
bitset<maxn>a[maxn],b[maxn];
struct qu{
	int S,T,num,ans,op;
}o[maxm];
struct node{
	int u,v,nxt;
}e[2][maxm],g[maxm];
inline int decode(char x,char y){
	int p=0;
	p=(x-'0')*50+y-'0';
	return p;
}
inline bool cmp(qu nx,qu ny){return nx.num<ny.num;}
inline bool cmp1(qu nx,qu ny){return nx.op<ny.op;}
inline void ipt(){
	tt=0;
	scanf("%lld%lld%lld",&n,&L,&q);
	for(int i=1;i<=n;i++)b[i]=0,fa[i]=i,b[i][i]=1;
	for(int i=1;i<=L;i++){
		scanf("%s",x);
		for(int j=0;j<2*n;j+=2)c[i][j/2+1]=decode(x[j],x[j+1]);
	}
//	for(int i=1;i<=L;i++){
//		for(int j=1;j<=n;j++)printf("%lld ",c[i][j]);
//		printf("\n");
//	}
	for(int i=1;i<=q;i++){
		scanf("%s",x);
		o[i].S=decode(x[0],x[1]);
		o[i].T=decode(x[2],x[3]);
		o[i].num=decode(x[4],x[5]);
		o[i].op=i;
		if(o[i].num==0){
			if(o[i].S==o[i].T)o[i].ans=1;
		}
	}
	sort(o+1,o+q+1,cmp);
}
inline void add0(int u,int v){
	e[0][++cnt[0]].v=v;
	e[0][cnt[0]].u=u;
	e[0][cnt[0]].nxt=head[0][u];
	head[0][u]=cnt[0];
}
inline bool make_graph(int k){
	cnt[0]=0;
	for(int i=1;i<=n;i++)head[0][i]=0;
	for(int i=1;i<=cnt[1];i++){
		int u=fa[e[1][i].u],v=fa[e[1][i].v];
		if(u==v)continue;
		add0(u,v);
	}
	for(int i=1;i<=n;i++)ct[i]=0;
	for(int i=1;i<=n;i++)ct[c[k][i]]++;
	int r=0;
	for(int i=1;i<=n;i++){
		if(ct[i]>2)return false;
		if(ct[i]==2)++r;
	}
	if(r>1)return false;
	if(r==0){
		for(int i=1;i<=n;i++)add0(fa[i],fa[c[k][i]]);
//		printf("k1 = %lld\n",k);
	}
	else {
//		printf("k2 = %lld\n",k);
		int s,s1=-1,s2=-1;
		for(int i=1;i<=n;i++){
			if(ct[i]==0)s=i;
			else if(ct[i]==2)r=i; 
		}
		for(int i=1;i<=n;i++){
			if(c[k][i]==r){
				if(s1==-1)s1=i;
				else s2=i;
			}
		}
		add0(fa[s1],fa[s]);
		add0(fa[s2],fa[s]);
	}
	return true;
}
stack<int>st;
inline void tarjan(int u){
	dfn[u]=low[u]=++tt;																																																																																																																																																				
	st.push(u);
	in[u]=true;
	for(int i=head[0][u];i;i=e[0][i].nxt){
		int v=e[0][i].v;
		if(!dfn[v]){
			tarjan(v);
			low[u]=min(low[v],low[u]);
		}
		else if(in[v])low[u]=min(low[v],low[u]);
	}
	if(low[u]==dfn[u]){
		int tmp;
		while(!st.empty()){
			tmp=st.top();
			st.pop();
			in[tmp]=false;
			fa[tmp]=u;
			if(u==tmp)break;
			b[u]|=b[tmp];
		}
	}
}
inline void add1(int u,int v){
	e[1][++cnt[1]].v=v;
	e[1][cnt[1]].u=u;
	e[1][cnt[1]].nxt=head[1][u];
	head[1][u]=cnt[1];
}
inline void add(int u,int v){
	g[++cnt_].v=v;
	g[cnt_].u=u;
	g[cnt_].nxt=h[u];
	h[u]=cnt_;	
}
inline void repair_graph(){
	cnt[1]=cnt_=0;
	for(int i=1;i<=n;i++)h[i]=head[1][i]=0;
	for(int i=1;i<=cnt[0];i++){
		int u=fa[e[0][i].u],v=fa[e[0][i].v];
		printf("just_revolutionary_oier\n");
		if(u==v)continue;
		printf("just_revolutionary_oier\n");
		add1(u,v);
		add(v,u);
		deg[u]++;
	}
}
queue<int>yt;
inline void topo_sort(){
	for(int i=1;i<=n;i++)a[i]=0;
	for(int i=1;i<=n;i++){
		a[i]=b[i];
		if(deg[i]==0)yt.push(i);
	}
	while(!yt.empty()){
		int u=yt.front();
		yt.pop();
		for(int i=h[u];i;i=g[i].nxt){
			int v=g[i].v;
			a[v]|=a[u];
			--deg[v];
			if(deg[v]==0)yt.push(v);
		}
	}
}
inline void query(int k){
	while(l<q+1){
		if(o[l].num==k){
			if(a[fa[o[l].S]][fa[o[l].T]])o[l].ans=1;
			else o[l].ans=0;
		}
		else if(o[l].num>k)break;
		++l;
	}
}
inline void solve(){
	l=1;
	for(int i=1;i<=L;i++){
		if(!make_graph(i)){
			query(i);
			continue;
		}
//		printf("I reached in Cheng Da community\n");
		tt=0;
		for(int j=1;j<=n;j++)dfn[j]=low[j]=0;
		for(int j=1;j<=n;j++){
			int u=fa[j];
			if(!dfn[u])tarjan(u);
		}
		repair_graph();
		topo_sort(); 
		query(i);
	}
	sort(o+1,o+q+1,cmp1);
	for(int i=1;i<=q;i++)printf("%lld",o[i].ans);
	printf("\n");
}
signed main(){
	scanf("%lld",&t);
	while(t--){
		ipt();
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9960kb

input:

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

output:

just_revolutionary_oier
just_revolutionary_oier
just_revolutionary_oier
just_revolutionary_oier
just_revolutionary_oier
1011
just_revolutionary_oier
just_revolutionary_oier
just_revolutionary_oier
just_revolutionary_oier
just_revolutionary_oier
just_revolutionary_oier
0100

result:

wrong answer 1st lines differ - expected: '1011', found: 'just_revolutionary_oier'