QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#566472 | #9319. Bull Farm | Uraboku | WA | 0ms | 7732kb | C++14 | 3.4kb | 2024-09-16 00:13:11 | 2024-09-16 00:13:11 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define O4 __inline__ __attribute__((always_inline))
#define inf 0x7fffffff
#define UL unsigned LL
#define LD long double
#ifdef ONLINE_JUDGE
#define getchar nc
#endif
//#define int LL
namespace FastIO{
O4 char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
O4 int read(){
char t;int u=0,k=1;t=getchar();
while(t<'0'||t>'9'){if(t==EOF)return -233;if(t=='-')k=-1;t=getchar();}
while(t>='0'&&t<='9'){u=u*10+t-'0';t=getchar();}
return u*k;
}
template <typename T>
O4 void read(T &u){
char t;T k=1;u=0;t=getchar();
while(t<'0'||t>'9'){if(t=='-')k=-1;t=getchar();}
while(t>='0'&&t<='9'){u=u*10+t-'0';t=getchar();}
if(t=='.'){
T mass=0.1;t=getchar();
while(t>='0'&&t<='9'){u+=mass*(t-'0');mass/=10;t=getchar();}
}u*=k;
}
O4 int read(char asd[]){
char t=getchar();int u=0;
while(t==' '||t=='\n'||t=='\r')t=getchar();
if(t==EOF)return -1;
while(t!=' '&&t!='\n'&&t!=EOF&&t!='\r')asd[u++]=t,t=getchar();
asd[u]='\0';return u;
}
// char sr[1<<23],z[23];int C=-1,Z;
// O4 void wer(int x,char T){
// int y=0;if(x<0)y=1,x=-x;
// while(z[++Z]=x%10+'0',x/=10);if(y)z[++Z]='-';
// while(sr[++C]=z[Z],--Z);sr[++C]=T;
// }
// O4 void wer(char T[],char QWQ){
// for(int i=0;T[i]!='\0';i++)sr[++C]=T[i];
// sr[++C]=QWQ;
// }
// O4 void out(){fwrite(sr,1,C+1,stdout);C=-1;}
}
using namespace std;
using namespace FastIO;
const int N=2005,M=1e6+5;
int n,q,l;
struct sss{
int a,b,c,num;
}que[M];
int mp[N][N],fa[N];
bool ans[M],vis[N];
char QwQ(){
char yy=getchar();
while(yy<48||yy>100)yy=getchar();
return yy;
}
int QWQ(){
int yy=(QwQ()-48)*50;
yy+=QwQ()-48;
return yy;
}
int get_fa(int x){
return fa[x]==x?x:fa[x]=get_fa(fa[x]);
}
vector <short int> to[N],qwe;
void link(int a,int b){
a=get_fa(a);b=get_fa(b);
if(a==b)return;
if(to[a].size()>to[b].size())swap(a,b);
fa[a]=b;
for(int i:to[a])
if(get_fa(i)!=b)to[b].push_back(i);
to[a]=qwe;
}
int rd[N];
void add(int x){
memset(rd,0,sizeof rd);
int a1=0,a2=0,ze=0;
for(int i=1;i<=n;i++){
int t=mp[x][i];
if(rd[t]){
if(a1)return;
a1=rd[t];
a2=i;
}
rd[t]=i;
}
if(!a1){
for(int i=1;i<=n;i++)link(i,mp[x][i]);
}
else{
for(int i=1;i<=n;i++)
if(rd[i]==0)ze=i;
if(ze==0)exit(233);
ze=get_fa(ze);
a1=get_fa(a1);
a2=get_fa(a2);
if(a1!=ze)to[a1].push_back(ze);
if(a2!=ze)to[a2].push_back(ze);
}
}
void DFS(int x){
vis[x]=1;
for(int i:to[x])
if(!vis[get_fa(i)])DFS(get_fa(i));
}
int yy=0;
void solve(){
n=read();l=read();q=read();
for(int i=1;i<=n;i++)to[i]=qwe;
for(int i=1;i<=n;i++)fa[i]=i;
for(int i=1;i<=l;i++)
for(int j=1;j<=n;j++)mp[i][j]=QWQ();
for(int i=1;i<=q;i++){
que[i].a=QWQ();
que[i].b=QWQ();
que[i].c=QWQ();
que[i].num=i;
}
if(yy<=11)return;
sort(que+1,que+1+q,[](sss a,sss b){return a.c<b.c;});
int now=0;
for(int i=1;i<=q;i++){
while(now!=que[i].c){
now++;
add(now);
}
memset(vis,0,sizeof vis);
DFS(get_fa(que[i].a));
ans[que[i].num]=vis[get_fa(que[i].b)];
}
for(int i=1;i<=q;i++)cout<<ans[i];cout<<'\n';
}
signed main(){
int T=read();
while(T--)solve();
}
/*
3
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7732kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
result:
wrong answer 1st lines differ - expected: '1011', found: ''