QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578663 | #9319. Bull Farm | xixixi | WA | 1ms | 5728kb | C++14 | 1.9kb | 2024-09-20 20:42:24 | 2024-09-20 20:42:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mxn=2e3+8;
int T,n,m1,m2,tot;
int h[mxn],temp[mxn],dp[mxn],vis[mxn],mp[mxn][mxn];
int pr[mxn];
int root(int x){
return pr[x]=(pr[x]==x?x:root(pr[x]));}
struct Star{
int to,w,nx;
}star[mxn*mxn];
void add(int x,int y,int w){
star[++tot].nx=h[x];
star[tot].to=y;
star[tot].w=w;
h[x]=tot;}
bool bfs(int st,int ed,int lim){
memset(vis,0,sizeof vis);
queue<int>q;
q.push(st);vis[st]=1;
while(q.size()){
int pre=q.front();q.pop();
for(int i=h[pre];~i;i=star[i].nx){
auto pto=star[i];
if(pto.w>lim||vis[pto.to])continue;
vis[pto.to]=1;q.push(pto.to);
if(pto.to==ed)return 1;
}
}
return vis[ed];
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> T;
while(T--){
cin >> n >> m1 >> m2 ;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
mp[i][j]=0;
for(int i=1;i<=n;i++)pr[i]=i;
memset(h,-1,sizeof h);
int from=0,to=0;tot=0;
for(int i=1;i<=m1;i++){
int sum = 0 ;
string s;cin >> s ;
for(int j=0;j<n;j++){
temp[j+1]=(s[j*2]-'0')*50+(s[j*2+1]-'0');dp[temp[j+1]]+=1;}
for(int j=1;j<=n;j++){
if(dp[j]==0)to=j;
if(dp[j]==2)from=j;
if(dp[j]){sum+=1,dp[j]=0;}}
if(sum==n){
for(int j=1;j<=n;j++){
int k=temp[j];
if(!mp[j][k]&&pr[j]!=pr[k])
add(j,k,i),mp[j][k]=1,pr[j]=root(k);}}
else if(sum==n-1)
for(int j=1;j<=n;j++){
if(temp[j]==from&&!mp[j][to]&&pr[j]!=pr[to])
add(j,to,i),mp[j][to]=1,pr[j]=root(to);}
}
for(int i=1;i<=m2;i++){
string s;cin >> s ;
int from,to,lim;
from=(s[0]-'0')*50+(s[1]-'0');
to=(s[2]-'0')*50+(s[3]-'0');
lim=(s[4]-'0')*50+(s[5]-'0');
cout << bfs(from,to,lim);
}
cout << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5728kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0000
result:
wrong answer 2nd lines differ - expected: '0100', found: '0000'