QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#521076#5504. Flower GardendczissbWA 2436ms102740kbC++143.3kb2024-08-15 20:56:342024-08-15 20:56:34

Judging History

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

  • [2024-08-15 20:56:34]
  • 评测
  • 测评结果:WA
  • 用时:2436ms
  • 内存:102740kb
  • [2024-08-15 20:56:34]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int head[1200001],t,heed[1200001],siz[1200001],toto,tot,tr[1200001],tt[1200001],stk1[1200001],du[1200001],ans,czc,cnt,ptt,n,m,x,y,xx,yy,dfn[1200001],low[1200001],color,col[1200001],vv[1200001],haed[1200001];struct dcz{int nex,to;}a[1200001],b[1200001],c[1200001];
stack<int> stk;

void add(int x,int y){
	a[++cnt].nex=head[x];
	a[cnt].to=y;
	head[x]=cnt;
}

void Add(int x,int y){
	b[++tot].nex=heed[x];
	b[tot].to=y;
	heed[x]=tot;
}

void AbbA(int x,int y){
	c[++czc].nex=haed[x];
	c[czc].to=y;
	haed[x]=czc;
}

void build(int l,int r,int root){
	if(l==r){
		tr[root]=tt[root]=l;
		return;
	}
	int p1=++ptt,p2=++ptt;
	tr[root]=p1,tt[root]=p2;
	int mid=l+r>>1;
	build(l,mid,root<<1);
	build(mid+1,r,root<<1|1);
	add(tr[root<<1],p1);
	add(tr[root<<1|1],p1);
	add(p2,tt[root<<1]);
	add(p2,tt[root<<1|1]);
}

void update(int L,int R,bool sum,int w,int l,int r,int root){
	if(L<=l&&r<=R){
		if(sum) add(tr[root],w);
		else add(w,tt[root]);
		return;
	}
	int mid=l+r>>1;
	if(L<=mid) update(L,R,sum,w,l,mid,root<<1);
	if(R>mid) update(L,R,sum,w,mid+1,r,root<<1|1);
}

void dfs(int u){
	dfn[u]=low[u]=++toto;
	stk.push(u);
	stk1[u]=1;
	for(int i=head[u];i;i=a[i].nex){
		int v=a[i].to;
		if(!dfn[v]){
			dfs(v);
			low[u]=min(low[u],low[v]);
		}
		else if(stk1[v]){
			low[u]=min(low[u],low[v]);
		}
	}
	if(dfn[u]==low[u]){
		col[u]=++color;
		siz[color]+=(u<=3*n);
		stk1[u]=0;
		while(stk.top()!=u){
			col[stk.top()]=color;
			siz[color]+=(stk.top()<=3*n);
			stk1[stk.top()]=0;
			stk.pop();
		}
		stk.pop();
	}
}
int dd(int u){
	if(vv[u]) return 0;
	vv[u]=1;
	int ans=siz[u];
	for(int i=haed[u];i;i=c[i].nex){
		int v=c[i].to;
		ans+=dd(v);
	}
	return ans;
}
void print(){
	cout<<"TAK\n";
	for(int i=1;i<=3*n;i++) cout<<(vv[col[i]]?"F":"R");
	cout<<"\n";
}
queue<int> q;
bool topu(){
	while(q.size()) q.pop();
	for(int i=1;i<=color;i++){
		if(!du[i]) q.push(i);
		vv[i]=0;
	}
	int ans=0;
	while(q.size()){
		int u=q.front();
		q.pop();
		if(ans+siz[u]>=2*n) continue;
		ans+=siz[u];
		vv[u]=1;
		if(ans>=n){print();return 1;}
		for(int i=heed[u];i;i=b[i].nex){
			int v=b[i].to;
			du[v]--;
			if(!du[v]) q.push(v);
		}
	}
	return 0;
}
signed main(){
	cin>>t;
	while(t--){
		cin>>n>>m;
		ptt=3*n;
		build(1,3*n,1);
		for(int i=1;i<=m;i++){
			cin>>x>>y>>xx>>yy;
			update(x,y,1,++ptt,1,3*n,1);
			update(xx,yy,0,ptt,1,3*n,1);
		}
		for(int i=1;i<=ptt;i++){/*cout<<dfn[i]<<endl;*/ if(!dfn[i]) dfs(i);}
		for(int i=1;i<=color;i++) du[i]=0;
		for(int i=1;i<=ptt;i++){
			for(int j=head[i];j;j=a[j].nex){
				int v=a[j].to;
				if(col[v]!=col[i]) AbbA(col[i],col[v]),Add(col[v],col[i]),du[col[i]]++;
			}
		}
//		for(int i=1;i<=3*n;i++) cout<<i<<" "<<col[i]<<endl;
		bool f=0;
		for(int i=1;i<=cnt;i++){
			if(siz[i]>=n){
				for(int j=1;j<=color;j++) vv[j]=0;
				if(dd(i)<=2*n){
					print();
					f=1;
					break;
				}
			}
		}
		if(!f){
			for(int j=1;j<=color;j++) vv[j]=0;
			if(!topu()) cout<<"NIE\n";
		}
		for(int i=1;i<=ptt;i++) head[i]=0;
		for(int i=1;i<=color;i++) siz[i]=0;
		for(int i=1;i<=ptt;i++) low[i]=0;
		for(int i=1;i<=ptt;i++) dfn[i]=0;
		for(int i=1;i<=ptt;i++) stk1[i]=0;
		toto=cnt=ptt=tot=czc=0;
		while(stk.size()) stk.pop();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 24236kb

input:

2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

output:

TAK
RRF
NIE

result:

ok good!

Test #2:

score: -100
Wrong Answer
time: 2436ms
memory: 102740kb

input:

10
33333 100000
28701 40192 93418 95143
95902 97908 78378 78461
36823 44196 22268 23996
23977 24786 33315 48829
83965 90411 4923 8445
20235 21177 32543 47454
29598 35414 72477 73049
2014 12632 42163 46466
64305 65518 98825 99552
32331 41625 92772 96224
26500 54122 76990 77126
18249 20335 31165 36080...

output:

TAK
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

result:

wrong answer zla odpowiedz!