如题,本题在洛谷上满分,但是在学校OJ提交只有30分(WA),求hack。
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > yyy(1005);
int ans[1005][1005];
bool tag[1005];
int i,j;
int n,m,q,x;
int a,b;
bool dfs(int y)
{
tag[y] = true;
if(b == y) return ans[y][b] = true;
if(ans[y][b] != -1) return ans[y][b];
int z = yyy[y].size();
for(int i = 0;i < z;++i)
{
if(tag[yyy[y][i]]) continue;
if(dfs(yyy[y][i])) return ans[y][b] = true;
}
return ans[y][b] = false;
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(i = 1;i <= m;++i)
{
for(j = 1;j <= n;++j)
{
scanf("%d",&x);
yyy[j].push_back(x);
}
}
for(i = 1;i <= n;++i)
{
for(j = 1;j <= n;++j)
{
ans[i][j] = -1;
}
}
for(i = 1;i <= q;++i)
{
for(int j = 1;j <= n;j++) tag[j] = 0;
scanf("%d %d",&a,&b);
if(dfs(a))
{
putchar('D');
putchar('A');
putchar('\n');
}
else
{
putchar('N');
putchar('E');
putchar('\n');
}
}
return 0;
}