QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#565941 | #9319. Bull Farm | Wolam | WA | 95ms | 9948kb | C++14 | 2.8kb | 2024-09-15 22:40:55 | 2024-09-15 22:40:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,m,q;
int fa[N];
int t[N][N];
bool vis[N][N];
bool ans[1000005];
struct ss{
int a,b,c,id;
bool operator <(const ss ot)const{
return c<ot.c;
}
}Q[1000005];
vector<int> g[2005],G[2005];
int find(int x)
{
if(x==fa[x])return x;
return fa[x]=find(fa[x]);
}
bool merge(int x,int y)
{
x=find(x);y=find(y);
if(x==y)return 1;
fa[x]=y;
return 0;
}
vector<int> e[N];
set<int> s;
void upd(int *t)
{
for(int i=1;i<=n;i++)
e[i].clear();
for(int i=1;i<=n;i++)
{
e[t[i]].push_back(i);
}
int mx=0,sum=0,mi=0;
for(int i=1;i<=n;i++)
{
if(e[i].size())
{
sum++;
if(e[i].size()>1)
mx=i;
}
else mi=i;
}
if(sum==n-1)
{
G[mi].push_back(e[mx][0]);
G[mi].push_back(e[mx][1]);
}
else if(!mx)
{
for(int i=1;i<=n;i++)
merge(i,t[i]);
}
for(int i=1;i<=n;i++)
g[i].clear();
for(int i=1;i<=n;i++)
{
int x=find(i);
for(auto j:G[i])
{
int y=find(j);
//cerr<<x<<" "<<y<<endl;
if(x!=y)g[x].push_back(y);
}
}
}
bool bfs(int s,int t,bool *vis)
{
for(int i=1;i<=n;i++)
vis[i]=0;
s=find(s);t=find(t);
queue<int> q;
q.push(s);
vis[s]=1;
while(!q.empty())
{
int x=q.front();q.pop();
for(auto y:g[x])
{
if(!vis[y])
{
q.push(y);
vis[y]=1;
}
}
}
return vis[t];
}
void sol()
{
cin>>n>>m>>q;
for(int i=1;i<=q;i++)
ans[i]=0;
for(int i=1;i<=n;i++)fa[i]=i,G[i].clear(),g[i].clear();
for(int i=1;i<=m;i++)
{
char a,b;
for(int j=1;j<=n;j++)
{
cin>>a>>b;
int x=(a-'0')*50+b-'0';
t[i][j]=x;
}
}
for(int i=1;i<=q;i++)
{
char a,b;
cin>>a>>b;
Q[i].a=(a-'0')*50+b-'0';
//cerr<<Q[i].a<<endl;
cin>>a>>b;
Q[i].b=(a-'0')*50+b-'0';
cin>>a>>b;
Q[i].c=(a-'0')*50+b-'0';
Q[i].id=i;
}
sort(Q+1,Q+q+1);
int now=1;
s.clear();
for(int i=1;i<=q;i++)
{
while(now<=Q[i].c)
{
// cerr<<now<<endl;
upd(t[now]);
now++;
s.clear();
}
if(s.count(find(Q[i].b)))
{
ans[Q[i].id]=vis[find(Q[i].b)][Q[i].id];
}
else
{
s.insert(find(Q[i].b));
ans[Q[i].id]=bfs(Q[i].b,Q[i].a,vis[find(Q[i].b)]);
}
}
for(int i=1;i<=q;i++)
cout<<ans[i];
cout<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// char a,b;
// for(char c=48;c<=98;c++)
// cerr<<c<<endl;
// cin>>a>>b;
int t;
for(cin>>t;t;t--){
sol();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7824kb
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: 0
Accepted
time: 0ms
memory: 9948kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
010101
result:
ok single line: '010101'
Test #3:
score: -100
Wrong Answer
time: 95ms
memory: 9856kb
input:
200 10 10 5000 01060:04020305080709 0103070:060204050908 09070503080401060:02 050308010204090:0607 03010502040607080:09 03080109020504060:07 06050:09040302080107 07080305010409060:02 030809010:0204060507 0:060908070201050304 060700 090:03 09080: 070405 010703 0:0100 080601 030600 070206 0:0:09 08040...
output:
000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '000000000100000000000000000000...0000000000000000000000000000000'