Submission #876407

#TimeUsernameProblemLanguageResultExecution timeMemory
876407JoksimKaktusKutije (COCI21_kutije)C++17
70 / 70
119 ms13748 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void output(bool yes){yes ? cout << "Yes" << "\n" : cout << "No" << "\n";} int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int n,m,q; cin >> n >> m >> q; vector <vector<int>>arr(n,vector<int>(m)); for(int i = 0;i < m;i++){ for(int j = 0;j < n;j++){ cin >> arr[j][i]; arr[j][i]--; } } vector <int> res(n,-1); for(int i = 0;i < n;i++){ if(res[i] != -1)continue; queue <int> qu; qu.push(i); while(!qu.empty()){ int j = qu.front(); qu.pop(); if(res[j] == i)continue; res[j]=i; for(int k : arr[j])qu.push(k); } } while(q--){ int a,b; cin >> a >> b; a--; b--; if(res[a] == res[b]){ cout << "DA\n"; }else{ cout << "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...