QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#565580 | #9319. Bull Farm | Mo_Han136 | WA | 2ms | 14084kb | C++20 | 4.0kb | 2024-09-15 21:44:46 | 2024-09-15 21:44:46 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=head[a];i;i=e[i].nxt)
using namespace std;
const int M=6005,Q=1e6+5;
int n,m,q,a[M][M],ans[Q],fl[M];
bool mk[M][M];
char s[M];
struct node{
int a,b,c,id;
bool operator < (const node &_)const{
return c<_.c;
}
}b[Q];
int d[M];
bitset<M> g[M];
int head[M],cnte,N,fa[M];
bool die[M];
struct edge{int to,nxt;}e[M*M];
void Add(int x,int y){
e[++cnte]=(edge){y,head[x]};
head[x]=cnte;
}
int FA(int x){return fa[x]==x?x:fa[x]=FA(fa[x]);}
queue<int> que;
vector<int> E[M],TMP;
int dfn[M],low[M],tot,inst[M],st[M],top;
void COPY(int x,int r){
erep(i,x){
int y=e[i].to;
y=FA(y);
if(y==r)continue;
Add(r,y);
}
g[r]|=g[x];
}
void dfs(int x){
dfn[x]=low[x]=++tot;
inst[st[++top]=x]=1;
erep(i,x){
int y=e[i].to;
if(!dfn[y])dfs(y),low[x]=min(low[x],low[y]);
else if(inst[y])low[x]=min(low[x],dfn[y]);
}
if(dfn[x]==low[x]){
int y;
++N;fa[N]=N;
g[N][N]=1;
TMP.clear();
while(inst[x]){
y=st[top--];
fa[y]=N;
inst[y]=0;
TMP.pb(y);
}
if(TMP.size()>1)
rep(i,0,TMP.size()-1)COPY(TMP[i],N);
}
}
void ADD(int p){
if(fl[p]==0)return;
rep(i,1,n)if(mk[p][i]){
int x=FA(i);
int y=FA(a[p][i]);
if(x!=y)Add(x,y);
}
rep(i,1,N)dfn[i]=inst[i]=0;
tot=top=0;
rep(x,1,N)if(!die[x] && !dfn[x])dfs(x);
rep(i,1,N)if(fa[i]!=i)die[i]=1;
rep(x,1,N)E[x].clear();
rep(x,1,N)d[x]=0;
rep(x,1,N)if(!die[x]){
erep(i,x){
int y=FA(e[i].to);
if(x==y)continue;
E[y].pb(x);++d[x];
}
}
rep(x,1,N)head[x]=0;cnte=0;
rep(x,1,N)if(!die[x]){
rep(i,0,E[x].size()-1){
int y=E[x][i];y=FA(y);
if(y==x)continue;
Add(y,x);
}
}
// rep(x,1,N)if(!die[x])printf("%d :%d\n",x,d[x]);
// printf("p %d N %d\n",p,N);
rep(x,1,N)if(!die[x] && !d[x])que.push(x);
while(!que.empty()){
int x=que.front();que.pop();
erep(i,x){
int y=e[i].to;
y=FA(y);
g[x]|=g[y];
}
rep(i,0,E[x].size()-1){
int y=E[x][i];
y=FA(y);
--d[y];
if(!d[y])que.push(y);
}
}
return;
}
void solve(){
scanf("%d%d%d",&n,&m,&q);
rep(i,1,m){
scanf("%s",s+1);
rep(j,1,n)a[i][j]=(s[j*2-1]-48)*50+(s[j*2]-48);
}
rep(i,1,m){
rep(j,1,n)d[j]=0;
int tmp=0;
rep(j,1,n){
++d[a[i][j]];
if(d[a[i][j]]>1)++tmp;
}
fl[i]=0;
if(tmp>1)continue;
if(tmp==1){
int pos=0;
rep(j,1,n)if(d[j]==0)pos=j;
rep(j,1,n)if(d[a[i][j]]>1)mk[i][j]=1,a[i][j]=pos;
fl[i]=1;
}
else{
rep(j,1,n)mk[i][j]=1;
fl[i]=2;
}
}
rep(i,1,q){
scanf("%s",s+1);
b[i].a=(s[1]-48)*50+(s[2]-48);
b[i].b=(s[3]-48)*50+(s[4]-48);
b[i].c=(s[5]-48)*50+(s[6]-48);
b[i].id=i;
}
sort(b+1,b+q+1);
int lst=0;
N=n;
rep(i,1,n)g[i][i]=1;
rep(i,1,n)fa[i]=i;
rep(i,1,q){
while(lst<b[i].c)ADD(++lst);
// printf("%d: %d -> %d\n",b[i].id,FA(b[i].a),FA(b[i].b));
ans[b[i].id]=g[FA(b[i].a)][FA(b[i].b)];
}
rep(i,1,q)printf("%d",ans[i]);puts("");
}
void clear(){
rep(i,1,m)fl[i]=0;
rep(i,1,m)rep(j,1,n)mk[i][j]=0;
rep(i,1,N)g[i].reset();
rep(i,1,N)die[i]=0;
rep(i,1,N)head[i]=0;
cnte=0;
}
int main(){
int t;scanf("%d",&t);
while(t--)clear(),solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 14084kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 12064kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
000100
result:
wrong answer 1st lines differ - expected: '010101', found: '000100'