QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#570648 | #9319. Bull Farm | yukino_yukinoshita | WA | 0ms | 10124kb | C++14 | 3.3kb | 2024-09-17 16:53:36 | 2024-09-17 16:53:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int M = 1e6 + 5;
int n, m, l, t[N][N];
int vis[N], flg[N], u1[N], u2[N], tt[N];
struct Qry {int a, b, c, id;} q[M];
bool cmp(Qry x, Qry y) {return x.c < y.c;}
bitset<2048> f[N];
int fa[N];
int find(int x) {return fa[x] == x ? x : fa[x] = find(fa[x]);}
void link(int x, int y)
{
for(int i = 1; i <= n; i++)
if(f[i][x]) f[i] |= f[y];
}
void merge(int x, int y)
{
x = find(x), y = find(y);
link(x, y), link(y, x);
fa[y] = x;
}
bool vs[N];
bool g[N][N];
bool bfs(int s, int t)
{
memset(vs, 0, sizeof(vs));
queue<int> que;
que.push(s); vs[s] = 1;
while(!que.empty())
{
int u = que.front(); que.pop();
if(u == t) return 1;
for(int i = 1; i <= n; i++) if(f[u][i] && !vs[i])
que.push(i), vs[i] = 1;
}
return 0;
}
void solve()
{
cin >> n >> l >> m;
for(int i = 1; i <= l; i++)
{
string s; cin >> s;
for(int j = 1; j <= n; j++) vis[j] = 0;
int cnt = 0;
for(int j = 1; j <= n; j++)
{
t[i][j] = 50 * (s[2 * j - 2] - '0') + s[2 * j - 1] - '0';
// cout << t[i][j] << " \n"[j == n];
if(vis[t[i][j]])
{
cnt++;
if(cnt == 1) flg[i] = 1, u1[i] = j, u2[i] = vis[t[i][j]];
else flg[i] = 2;
}
vis[t[i][j]] = j;
}
if(flg[i] == 1)
{
for(int j = 1; j <= n; j++) if(!vis[j])
{
tt[i] = j;
break;
}
}
}
// cout << "\n";
for(int i = 1; i <= m; i++)
{
string s; cin >> s;
q[i].a = 50 * (s[0] - '0') + s[1] - '0';
q[i].b = 50 * (s[2] - '0') + s[3] - '0';
q[i].c = 50 * (s[4] - '0') + s[5] - '0';
q[i].id = i;
// cerr << q[i].a << " " << q[i].b << " " << q[i].c << "\n";
}
sort(q + 1, q + m + 1, cmp);
memset(vis, 0, sizeof(vis));
for(int i = 1; i <= n; i++) f[i][i] = 1, fa[i] = i;
memset(g, 0, sizeof(g));
string ans; ans.resize(m);
for(int i = 1, cc = 1; i <= m; i++)
{
for(; cc <= q[i].c; cc++)
{
if(flg[cc] == 2) continue;
if(flg[cc] == 1)
{
g[u1[cc]][tt[cc]] = 1;
g[u2[cc]][tt[cc]] = 1;
continue;
}
for(int u = 1; u <= n; u++) if(vis[u] == 0)
{
int st = u;
bool ok = 0;
bitset<2048> to, from;
for(int x = u; !vis[x]; x = t[cc][x])
{
vis[x] = 1;
if(find(x) != find(st)) merge(st, u);
g[st][x] = g[x][st] = 1;
}
}
}
// ans[q[i].id - 1] = f[q[i].a][q[i].b] + '0';
ans[q[i].id - 1] = bfs(q[i].a, q[i].b) + '0';
}
cout << ans << "\n";
for(int i = 1; i <= n; i++) f[i].reset();
for(int i = 1; i <= l; i++) flg[i] = 0;
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T; cin >> T;
while(T--) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 10124kb
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'