#include <bits/stdc++.h>
using namespace std;
const int M = 1001;
vector<int> nei[M];
int nm[M],cc;
bool vis[M];
void dfs(int u)
{
vis[u]=1;
nm[u]=cc;
for (int i:nei[u])
if (!vis[i])
dfs(i);
}
int main()
{
int n,m,q;
cin>>n>>m>>q;
int a[n+1];
for (int i=0;i<m;i++)
{
for (int i=1;i<=n;i++)
cin>>a[i];
for (int i=1;i<=n;i++)
{
nei[i].push_back(a[i]);
nei[a[i]].push_back(i);
}
}
for (int i=1;i<=n;i++)
{
if (!vis[i])
{
dfs(i);
cc++;
}
}
while (q--)
{
int a,b;
cin>>a>>b;
if (nm[a]==nm[b])
cout<<"DA"<<'\n';
else
cout<<"NE"<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
739 ms |
1840 KB |
Output is correct |
2 |
Correct |
597 ms |
1596 KB |
Output is correct |
3 |
Correct |
560 ms |
1620 KB |
Output is correct |
4 |
Correct |
654 ms |
1872 KB |
Output is correct |
5 |
Correct |
654 ms |
1852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
584 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
584 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
739 ms |
1840 KB |
Output is correct |
2 |
Correct |
597 ms |
1596 KB |
Output is correct |
3 |
Correct |
560 ms |
1620 KB |
Output is correct |
4 |
Correct |
654 ms |
1872 KB |
Output is correct |
5 |
Correct |
654 ms |
1852 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
584 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
892 ms |
10780 KB |
Output is correct |
27 |
Correct |
816 ms |
10776 KB |
Output is correct |
28 |
Correct |
637 ms |
9552 KB |
Output is correct |
29 |
Correct |
746 ms |
10576 KB |
Output is correct |
30 |
Correct |
645 ms |
9040 KB |
Output is correct |
31 |
Correct |
677 ms |
9536 KB |
Output is correct |
32 |
Correct |
863 ms |
10008 KB |
Output is correct |
33 |
Correct |
825 ms |
9876 KB |
Output is correct |
34 |
Correct |
788 ms |
10064 KB |
Output is correct |
35 |
Correct |
797 ms |
10420 KB |
Output is correct |