#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll long long int
#define oo 1e18 + 5
#define pii pair<int, int>
const int MAX = 1005;
bool visited[MAX];
set<int> g[MAX];
bitset<MAX> accesible[MAX];
void dfs(int node, int par){
visited[node] = true;
accesible[par][node] = true;
accesible[node][par] = true;
for(int to : g[node]){
if(!visited[to]){
dfs(to, node);
accesible[node] |= accesible[to];
accesible[to] = accesible[node];
}
}
}
int main(){
int n, m, q; cin >> n >> m >> q;
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
int a; cin >> a;
g[j].insert(a);
g[a].insert(j);
}
}
for (int i = 1; i <= n; i++)
{
if(!visited[i]){
dfs(i, i);
}
}
while(q--){
int a, b; cin >> a >> b;
if(accesible[a][b]){
cout << "DA\n";
}
else{
cout << "NE\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
785 ms |
2916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
785 ms |
2916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |