Submission #496637

#TimeUsernameProblemLanguageResultExecution timeMemory
496637JovanBKutije (COCI21_kutije)C++17
70 / 70
175 ms13544 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 1000; vector <int> graf[N+5]; bool visited[N+5]; int comp[N+5]; void dfs(int v, int p){ comp[v] = p; visited[v] = 1; for(auto c : graf[v]) if(!visited[c]) dfs(c, p); } int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m, qrs; cin >> n >> m >> qrs; int cnt = 0; for(int j=1; j<=m; j++){ for(int i=1; i<=n; i++){ int x; cin >> x; graf[i].push_back(x); graf[x].push_back(i); } } for(int i=1; i<=n; i++){ if(!comp[i]){ cnt++; dfs(i, cnt); } } while(qrs--){ int a, b; cin >> a >> b; cout << (comp[a] == comp[b] ? "DA\n" : "NE\n"); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...