Submission #724558

#TimeUsernameProblemLanguageResultExecution timeMemory
724558TahirAliyevKutije (COCI21_kutije)C++17
35 / 70
1004 ms7820 KiB
#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]; bool accessible[MAX][MAX]; void dfs(int node, vector<int> path){ visited[node] = true; path.push_back(node); for(int a : path){ accessible[a][node] = true; accessible[node][a] = true; } for(int to : g[node]){ if(!visited[to]){ dfs(to, path); } } } 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, vector<int>()); } } while(q--){ int a, b; cin >> a >> b; if(accessible[a][b]){ cout << "DA\n"; } else{ cout << "NE\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...