QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592267 | #9319. Bull Farm | laonongmin | WA | 1ms | 5748kb | C++17 | 3.8kb | 2024-09-26 21:40:29 | 2024-09-26 21:40:30 |
Judging History
answer
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define N 2005
#define MOD 998244353
using namespace std;
vector<int> e[N];
int dfn[N], low[N], tot, st[N], inst[N], top, fa[N];
void tarjan(int u)
{
dfn[u] = low[u] = ++tot;
st[++top] = u; inst[u] = 1;
for(auto &&v:e[u])
{
if(!dfn[v])
{
tarjan(v);
low[u] = min(low[u], low[v]);
}
else if(inst[v]) low[u] = min(low[u], dfn[v]);
}
if(dfn[u] == low[u])
{
int v;
do{
v = st[top--]; inst[v] = 0;
fa[v] = u;
}while(v != u);
}
}
int rt(int x)
{
while(x!=fa[x]) x=fa[x]=fa[fa[x]];
return x;
}
bitset<N> vis;
void dfs(int u)
{
for(auto &&v:e[u])
{
if(vis[v]) continue;
vis[v]=1;
dfs(v);
}
}
int t[N][N];
int nt[N];
bitset<N> ans;
struct query{
int a,b,id;
};
vector<query> qs[N];
void solve()
{
int n,l,q;
cin>>n>>l>>q;
for(int i=1;i<=n;++i) {e[i].clear(); fa[i]=i;}
for(int i=1;i<=l;++i) {qs[i].clear();}
for(int i=1;i<=l;++i)
{
string s;
cin>>s;
for(int j=1;j<=n;++j) t[i][j] = (s[2*(j-1)]-48)*50 + (s[2*(j-1)+1]-48);
}
for(int i=1;i<=q;++i)
{
string s;
cin>>s;
int a = (s[0]-48)*50 + (s[1]-48);
int b = (s[2]-48)*50 + (s[3]-48);
int c = (s[4]-48)*50 + (s[5]-48);
// cout<<a<<' '<<b<<' '<<c<<'\n';
qs[c].push_back({a,b,i});
}
for(auto &&[a,b,id]:qs[0]) ans[id]=(a==b);
for(int c=1;c<=l;++c)
{
// add
for(int i=1;i<=n;++i) nt[i] = 0;
int t1=0,t2=0;
int ok=2;
for(int i=1;i<=n;++i)
{
if(!nt[t[c][i]]) nt[t[c][i]] = i;
else
{
t1=i; t2=nt[t[c][i]];
ok -= 2;
}
}
if(!t1 && !t2)
{
for(int i=1;i<=n;++i)
{
if(rt(i) != rt(t[c][i]))
e[rt(i)].push_back(rt(t[c][i]));
}
}
else if(ok>0)
{
for(int i=1;i<=n;++i)
{
if(!nt[i])
{
int z=i;
t1=rt(t1), t2=rt(t2), z=rt(z);
if(t1 != z) e[t1].push_back(z);
if(t2 != z) e[t2].push_back(z);
break;
}
}
}
// tarjan
tot=0; top=0;
for(int i=1;i<=n;++i) {dfn[i]=0; inst[i]=0;}
for(int i=1;i<=n;++i) if(!dfn[i] && rt(i)==i) tarjan(i);
for(int i=1;i<=n;++i)
{
if(rt(i) != i)
{
for(auto &&v:e[i]) if(rt(v) != rt(i)) e[rt(i)].push_back(rt(v));
e[i].clear();
}
}
for(int i=1;i<=n;++i)
{
if(rt(i) == i)
{
for(int i=1;i<=n;++i) vis[i]=0;
vector<int> pe = e[i];
e[i].clear();
for(auto &&v:pe)
{
v=rt(v);
if(v != i && !vis[v]) {e[i].push_back(v); vis[v]=1;}
}
}
}
// cal
for(auto &&[a,b,id]:qs[c])
{
for(int i=1;i<=n;++i) vis[i]=0;
a=rt(a); b=rt(b);
vis[a]=1;
dfs(a);
ans[id] = vis[b];
}
}
// for(int i=1;i<=n;++i) cout<<rt(i)<<'\n';
for(int i=1;i<=q;++i) cout<<ans[i];
cout<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3912kb
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: 1ms
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'