QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592245 | #9319. Bull Farm | laonongmin | WA | 90ms | 5324kb | C++17 | 3.9kb | 2024-09-26 21:30:00 | 2024-09-26 21:30:00 |
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, int last)
{
dfn[u] = low[u] = ++tot;
st[++top] = u; inst[u] = 1;
for(auto &&v:e[u])
{
if(!dfn[v])
{
tarjan(v, u);
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;
bool ok=true;
for(int i=1;i<=n;++i)
{
if(!nt[t[c][i]]) nt[t[c][i]] = i;
else
{
if(t1) ok=false;
t1=i; t2=nt[t[c][i]];
}
}
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)
{
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,0);
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: 0ms
memory: 3696kb
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: 3940kb
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: 90ms
memory: 5324kb
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:
011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110001101101111111111111111...1111111111111111101111111111111'