RT,本人写了个疑似O(N^2M)(大概这个数量级)的做法,但是不知道为什么第二个substack就过不去了,也不想卡长了,求高人指点一下这题的做法(BFS想不出来了)
本人代码。仅供参考,不必须看其实
#include<bits/stdc++.h>
using namespace std;
vector <int> edge[1005];
queue <int> q;
int n,m,ask;
bool vis[1005],can[1005][1005];
int main(){
cin>>n>>m>>ask;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
int x;
cin>>x;
edge[j].push_back(x);
}
}
for(int i=1;i<=n;i++){
memset(vis,false,sizeof(vis));
q.push(i);
can[i][i]=true;
while(!q.empty()){
int x=q.front();
q.pop();
vis[x]=true;
for(auto k:edge[x]){
if(vis[k]==false){
can[i][k]=true;
q.push(k);
}
}
}
}
while(ask--){
int a,b;
cin>>a>>b;
if(can[a][b])
cout<<"DA"<<endl;
else
cout<<"NE"<<endl;
}
return 0;
}