社区讨论
求解释
P11230[CSP-J 2024] 接龙参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @m2qzlqsj
- 此快照首次捕获于
- 2024/10/27 10:44 去年
- 此快照最后确认于
- 2024/10/27 11:58 去年
为啥骗分代码一分没有?
CPP#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int N=100001;
vector<int>v[N];
vector<pair<int,int> >st[2*N];
int t,n,k,q,l[N],r,c,tt;
bool ans;
void dfs(int s,int t,int u){
if(u==r){
if(s==c) ans=true;
return;
}
for(pair<int,int> xyy:st[s]){
if(ans) return;
if(xyy.first==t) continue;
for(int j=xyy.second+1;j<xyy.second+k;j++){
if(ans) return;
dfs(v[xyy.first][j],xyy.first,u+1);
}
}
}
int main(){
//ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>n>>k>>q;
for(int i=1;i<=n;i++){
v[i].clear();
st[i].clear();
}
for(int i=1;i<=n;i++){
cin>>l[i];
for(int j=1;j<=l[i];j++){
cin>>tt;
v[i].push_back(tt);
st[tt].push_back({i,j-1});
}
}
while(q--){
cin>>r>>c;
ans=false;
dfs(1,-1,0);
cout<<ans<<endl;
}
}
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...