QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#521108 | #5504. Flower Garden | dczissb | WA | 0ms | 24360kb | C++14 | 3.3kb | 2024-08-15 21:21:16 | 2024-08-15 21:21:17 |
Judging History
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;
for(int i=1;i<=color;i++){
if(siz[i]>=n){
for(int j=1;j<=color;j++) vv[j]=0;
if(dd(i)<=2*n){
print();
break;
}
}
}
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<=toto;i++) low[i]=0;
for(int i=1;i<=toto;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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 24360kb
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 TAK RRF NIE
result:
wrong answer zla odpowiedz!