QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571497 | #9319. Bull Farm | ATM12345 | WA | 1ms | 5696kb | C++14 | 2.6kb | 2024-09-17 23:40:13 | 2024-09-17 23:40:13 |
Judging History
answer
#include <bits/stdc++.h>
#define ll int
#define LL long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 2005
#define pb push_back
#define ld long double
#define all(x) x.begin(),x.end()
using namespace std;
ll n,m,q;
ll inf=1e9;
ll a[N][N];
ll dp[N][N];
ll ask(ll x,ll y)
{
return (x-48)*50+(y-48);
}
ll ru[N],vis[N];
ll fa[N];
ll find(ll x)
{
if (fa[x]==x) return fa[x];
return fa[x]=find(fa[x]);
}
struct node {
ll be,e,w;
};
vector <node> v[N];
ll dis[N];
struct que{
ll num,w;
bool operator <(const que &A)const{
return w>A.w;
}
};
void dij(ll x)
{
for (ll i=1;i<=n;i++)
dis[i]=inf,vis[i]=0;
priority_queue <que> q;
vis[x]=1,dis[x]=0;
q.push({x,0});
while (!q.empty())
{
que p=q.top();
q.pop();
if (vis[p.num])
continue;
dis[p.num]=p.w;
for (auto z:v[p.num])
q.push({z.e,max(z.w,p.w)});
}
for (ll i=1;i<=n;i++)
dp[x][i]=dis[i];
}
void goline(ll x,ll y,ll ti) //x->y
{
v[x].pb({x,y,ti});
return;
}
void merage(ll x,ll y,ll id)
{
x=find(x),y=find(y);
if (x==y)
return ;
goline(x,y,id),goline(y,x,id);
fa[y]=x;
return ;
}
void dfs(ll id,ll x)
{
vis[x]=1;
while (!vis[a[id][x]])
merage(x,a[id][x],id),x=a[id][x],vis[x]=1;
return;
}
void go(ll x)
{
for (ll i=1;i<=n;i++)
ru[i]=0;
ll cnt=0;
for (ll i=1;i<=n;i++)
{
ru[a[x][i]]++;
if (ru[a[x][i]]==2)
cnt++;
if (ru[a[x][i]]>2)
return;
}
if (cnt>=2)
return;
ll z=0;
for (ll i=1;i<=n;i++)
if (!ru[i])
z=i;
if (cnt)
{
//printf("OK1\n");
for (ll i=1;i<=n;i++)
{
if (ru[a[x][i]]==2)
goline(i,z,x);
}
return;
}
//printf("OK0\n");
for (ll i=1;i<=n;i++)
vis[i]=0;
for (ll i=1;i<=n;i++)
if (!vis[i])
dfs(x,i);
return;
}
void sol()
{
cin>>n>>m>>q;
for (ll i=1;i<=n;i++)
fa[i]=i,v[i].clear();
for (ll i=1;i<=n;i++)
{
for (ll j=1;j<=n;j++)
dp[i][j]=inf;
dp[i][i]=0;
}
for (ll i=1;i<=m;i++)
{
string s;
cin>>s;
for (ll j=1;j<=n;j++)
a[i][j]=ask(s[j*2-2],s[j*2-1]);
go(i);
}
for (ll i=1;i<=n;i++)
dij(i);
for (ll i=1;i<=q;i++)
{
string s;
cin>>s;
ll x=ask(s[0],s[1]),y=ask(s[2],s[3]),z=ask(s[4],s[5]);
if (dp[x][y]<=z)
cout<<1;
else
cout<<0;
}
cout<<"\n";
return;
}
int main()
{
IOS
ll tt=1;
cin>>tt;
while (tt--)
sol();
return 0;
}
/*
1
4 2 1
02010403
01040402
010402
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5696kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1000 0000
result:
wrong answer 1st lines differ - expected: '1011', found: '1000'