QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572698 | #9319. Bull Farm | zjx666 | WA | 1ms | 7740kb | C++17 | 2.2kb | 2024-09-18 15:59:45 | 2024-09-18 15:59:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=4010;
int n,l,qi;
int ti[maxn][maxn];
struct A{int x,y,z;
};
A e[2*maxn];//注意两倍
int head[maxn],ne[maxn*2];//head初始化为-1
int d[maxn][maxn];
int f[maxn];
bool v[maxn];
int di[maxn];
int id=-1;
int find (int x)
{
if(x!=f[x])f[x]=find(f[x]);
return f[x];
}
void add(int x,int y,int z)
{
e[++id]={x,y,z};
ne[id]=head[x];
head[x]=id;
}
priority_queue<pair<int,int> >q;
void dij(int fx)
{
for(int i=0;i<=n;i++)
{
d[fx][i]=1e9+10;
v[i]=0;
}
d[fx][fx]=0;
q.push({-d[fx][fx],fx});
while(q.size())
{
while(q.size()&&v[q.top().second])q.pop();
if(q.empty())break;
int x=q.top().second;
v[x]=1;
q.pop();
for(int i=head[x];i!=-1;i=ne[i])
{
int y=e[i].y;
if(d[fx][y]>max(d[fx][x],e[i].z))
{
d[fx][y]=max(d[fx][x],e[i].z);
q.push({-d[fx][y],y});
}
}
}
}
void build()
{
for(int i=1;i<=l;i++)
{
int s=0;
for(int j=1;j<=n;j++)
{
if(!di[ti[i][j]])
{
di[ti[i][j]]=1;
s++;
}
else
{
di[ti[i][j]]++;
}
}//cout<<s<<"!!"<<endl;
if(s==n)
{
for(int j=1;j<=n;j++)
{
find(j);
find(ti[i][j]);
if(f[j]!=f[ti[i][j]])
{
f[f[j]]=f[ti[i][j]];
add(j,ti[i][j],i);
add(ti[i][j],j,i);
}
}
}
else if(s==n-1)
{
for(int j=1;j<=n;j++)
{
if(di[j]==0)
{
for(int k=1;k<=n;k++)
{
if(ti[i][k]==j)add(k,j,i);
}
}
}
}
for(int j=1;j<=n;j++)di[j]=0;
}
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n>>l>>qi;
id=-1;
for(int i=1;i<=2*n;i++)
{
head[i]=-1;
f[i]=i;
}
for(int i=1;i<=l;i++)
{
for(int j=1;j<=n;j++)
{
char x,y;
cin>>x>>y;
//cout<<x<<"!"<<y<<"!";
ti[i][j]=(x-48)*50+y-48;
}
}
build();
for(int i=1;i<=n;i++)dij(i);
for(int i=1;i<=qi;i++)
{
char x1,y1,x2,y2,x3,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
int a=(x1-48)*50+y1-48;
int b=(x2-48)*50+y2-48;
int c=(x3-48)*50+y3-48;
if(d[a][b]<=c)cout<<1;
else cout<<0;
}
cout<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7740kb
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: 5748kb
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'