QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#571339 | #9319. Bull Farm | zqx | WA | 72ms | 3936kb | C++23 | 4.6kb | 2024-09-17 22:06:03 | 2024-09-17 22:06:03 |
Judging History
answer
#include<bits/stdc++.h>
#define AC return 0;
#define int long long
#define pii pair<int,int>
#define all(tar) tar.begin(),tar.end()
const int maxx=2005;
const int mod=1e9+7;
using namespace std;
int n,m,t,low[maxx],dfn[maxx],idx,top;
int _stack[maxx],scc[maxx],instack[maxx],sc,sz[maxx];
vector<int>G[maxx];
vector<int>g[maxx];
int read() {
char u, v;
cin >> u >> v;
return (u - 48) * 50 + v - 48;
}
int fa[maxx],siz[maxx];
int get_fa(int u){
return fa[u]==u?u:fa[u]=get_fa(fa[u]);
}
void merge(int u,int v){
if(get_fa(v)==get_fa(u))return ;
u=get_fa(u),v=get_fa(v);
if(siz[u]>siz[v]){
swap(u,v);
}
siz[u]+=siz[v];
fa[v]=u;
}
bool check(int u,int v){
return get_fa(u)!=get_fa(v);
}
bool ans[maxx];
void tarjan(int u) {
low[u] = dfn[u] = ++idx;
_stack[++top] = u;
instack[u] = 1;
for (auto v : G[u]) {
if(get_fa(v)==get_fa(u))continue;
if (!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
} else if (instack[v]) {
low[u] = min(low[u], dfn[v]);
}
}
if (dfn[u] == low[u]) {
int y;
do {
y = _stack[top];
instack[y] = 0;
merge(u,y);
--top;
} while (y != u);
}
}
int in[maxx];
vector<pair<int,int>>edge[maxx];
struct Q{
int u,v,id;
};
bitset<2005>dp[2005];
vector<Q>qu[maxx];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T--){
cin>>n>>m>>t;
for(int i=1;i<=n;i++)G[i].clear(),dp[i].reset();
for(int i=0;i<=m;i++)edge[i].clear(),qu[i].clear();
for(int k=1;k<=m;k++){
vector<int>p(n+1);
vector<int>cnt(n+1,0);
int zero=0,_2=0;
for(int i=1;i<=n;i++)p[i]=read(),cnt[p[i]]++;
bool flag=1;
for(int i=1;i<=n;i++){
if(cnt[i]>2){
flag=0;
break;
}
if(cnt[i]==0){
if(!zero){
zero=i;
}
else {
flag=0;
break;
}
}
if(cnt[i]==2){
if(!_2){
_2=i;
}
else {
flag=0;
break;
}
}
}
if(flag){
if(!zero){
for(int i=1;i<=n;i++){
edge[k].push_back({i,p[i]});
}
}
else {
for(int i=1;i<=n;i++){
if(cnt[p[i]]==2){
edge[k].push_back({i,zero});
}
}
}
}
}
for(int i=1;i<=n;i++){
fa[i]=i;
siz[i]=1;
}
for(int i=1;i<=t;i++){
int u,v,c;
ans[i]=0;
u=read();
v=read();
c=read();
qu[c].push_back({u,v,i});
}
for(int c=0;c<=m;c++){
idx=0;
top=0;
for(int i=1;i<=n;i++){
dfn[i]=low[i]=0;
instack[i]=0;
}
for(auto [u,v]:edge[c]){
if(check(u,v)){
// cout<<v<<" "<<u<<'\n';
G[get_fa(v)].push_back(get_fa(u));
}
}
for(int i=1;i<=n;i++){
if(!dfn[get_fa(i)]){
tarjan(get_fa(i));
}
}
for(int i=1;i<=n;i++){
if(i!=fa[i]){
for(auto v:G[i]){
G[get_fa(i)].push_back(get_fa(v));
}
G[i].clear();
}
}
if(c==3){
}
for(int i=1;i<=n;i++){
if(fa[i]==i){
vector<int>vec;
for(auto v:G[i]){
if(get_fa(v)!=i)vec.push_back(v);
}
sort(all(vec));
vec.erase(unique(all(vec)),vec.end());
G[i]=vec;
}
}
for(int i=1;i<=n;i++){
dp[get_fa(i)][i]=1;
in[i]=0;
}
queue<int>q;
for(int i=1;i<=n;i++){
if(fa[i]==i){
for(auto v:G[i]){
if(check(v,i))
in[get_fa(v)]++;
}
}
}
for(int i=1;i<=n;i++){
if(fa[i]==i&&!in[i])q.push(i);
}
while(!q.empty()){
int u=q.front();
q.pop();
for(auto v:G[u]){
in[v]--;
dp[v]|=dp[u];
if(!in[v])q.push(v);
}
}
for(auto [u,v,id]:qu[c]){
if(dp[get_fa(u)][get_fa(v)])ans[id]=1;
}
}
for(int i=1;i<=t;i++){
cout<<ans[i];
}
cout<<'\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3700kb
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: 3936kb
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: 72ms
memory: 3824kb
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'