#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 = 105;
bool visited[MAX];
set<int> g[MAX];
bool dfs(int node, int target){
if(node == target) return true;
visited[node] = true;
for(int to : g[node]){
if(!visited[to]){
if(dfs(to, target)){
return true;
}
}
}
return false;
}
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++)
{
cout << i << ": ";
for(int a : g[i]){
cout << a << ' ';
}
cout << '\n';
}
while(q--){
memset(visited, 0, sizeof(visited));
int a, b; cin >> a >> b;
if(dfs(a, b)){
cout << "DA\n";
}
else{
cout << "NE\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |