QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592306 | #9319. Bull Farm | laonongmin | WA | 87ms | 5848kb | C++17 | 3.7kb | 2024-09-26 21:51:27 | 2024-09-26 21:51:29 |
Judging History
answer
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define N 2005
#define Q 1000005
#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<Q> ans;
struct query{
int a,b,id;
};
vector<query> qs[N];
char s[N];
map<pii,int> mp;
void solve()
{
int n,l,q;
cin>>n>>l>>q;
mp.clear();
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)
{
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)
{
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 -= 1;
}
}
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 && e[i].size())
{
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)
{
sort(e[i].begin(), e[i].end());
auto pos = unique(e[i].begin(), e[i].end());
e[i].erase(pos, e[i].end());
}
}
// 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: 5848kb
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: 3804kb
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: 87ms
memory: 5172kb
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:
011110001101101111111101111111100100111111110110011110010110111011010101111110101111111101111111111110111111110011111101111101101011111110101111111111111101110001100111111111111111011111111011001111111111111111011101111011011011111011011011110100011110011111110111111100111111101110011110111101111110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110001101101111111101111111...1111111111011011101101111111111'