QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#826 | #565784 | #9319. Bull Farm | UESTC_OldEastWest | bulijiojiodibuliduo | Failed. | 2024-09-17 14:28:36 | 2024-09-17 14:28:37 |
Details
Extra Test:
Accepted
time: 1ms
memory: 5768kb
input:
1 5 3 1 0504010502 0402050305 0202010403 040102
output:
1
result:
ok single line: '1'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#565784 | #9319. Bull Farm | bulijiojiodibuliduo# | AC ✓ | 201ms | 37004kb | C++17 | 2.2kb | 2024-09-15 22:14:17 | 2024-09-15 22:14:18 |
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=2010;
int n,l,q,f[N],g[N],vis[N],dis[N],pc[N],qc[N][N],ans[N][N];
vector<PII> e[N];
string s;
int find(int x) {
return f[x]==x?x:f[x]=find(f[x]);
}
void solve() {
cin>>n>>l>>q;
rep(j,0,n) f[j]=j,e[j].clear();
rep(i,1,l+1) {
cin>>s;
rep(j,0,n) vis[j]=0;
rep(j,0,n) {
g[j]=(s[j*2]-'0')*50+(s[j*2+1]-'0')-1;
vis[g[j]]+=1;
}
int sz=0;
rep(j,0,n) sz+=vis[j]!=0;
if (sz<=n-2) continue;
if (sz==n) {
rep(j,0,n) {
if (find(j)!=find(g[j])) {
f[find(j)]=find(g[j]);
e[j].pb(mp(g[j],i));
e[g[j]].pb(mp(j,i));
}
}
} else {
int mc2=-1,mc0=-1;
rep(j,0,n) {
if (vis[j]==2) mc2=j;
if (vis[j]==0) mc0=j;
}
assert(mc2!=-1&&mc0!=-1);
rep(j,0,n) if (g[j]==mc2) e[j].pb(mp(mc0,i));
}
}
rep(S,0,n) {
rep(i,0,l+1) pc[i]=0;
rep(i,0,n) dis[i]=1<<30,vis[i]=0;
dis[S]=0;
qc[0][pc[0]++]=S;
rep(rd,0,l+1) {
rep(i,0,pc[rd]) {
int u=qc[rd][i];
if (vis[u]) continue;
vis[u]=1;
for (auto [v,w]:e[u]) {
if (dis[v]>max(dis[u],w)) {
dis[v]=max(dis[u],w);
qc[dis[v]][pc[dis[v]]++]=v;
}
}
}
}
rep(i,0,n) ans[S][i]=dis[i];
}
string ret;
rep(i,0,q) {
cin>>s;
rep(j,0,3) g[j]=(s[j*2]-'0')*50+(s[j*2+1]-'0')-1;
//g[0]--; g[1]--;
g[2]++;
if (ans[g[0]][g[1]]<=g[2]) ret.pb('1'); else ret.pb('0');
}
cout<<ret<<"\n";
}
int _;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (cin>>_;_;_--) {
solve();
}
}