Submission #798791

#TimeUsernameProblemLanguageResultExecution timeMemory
798791Tunglam07Kutije (COCI21_kutije)C++17
25 / 70
688 ms6584 KiB
#include<bits/stdc++.h> using namespace std; long long n, m, q, a[1001][1001], pos1, pos2; bool ck[1001][1001]; void check(int pos1, int pos2) { if(ck[pos1][pos2]) { return; } ck[pos1][pos2] = true; check(pos1, a[1][pos2]); } int main() { cin >> n >> m >> q; if(m == 1) { for(int i = 1; i <= n; ++i) { cin >> a[1][i]; } for(int i = 1; i <= n; ++i) { check(i, i); } while(q--) { cin >> pos1 >> pos2; if(ck[pos1][pos2]) { cout << "DA" << endl; } else { cout << "NE" << endl; } } } else { for(int i = 1; i <= m; ++i) { for(int j = 1; j <= n; ++j) { cin >> a[i][j]; } } for(int i = 1; i <= m; ++i) { for(int j = 1; j <= m; ++j) { for(int l = 1; l <= n; ++l) { ck[l][l] = true; ck[l][a[i][l]] = true; ck[l][a[j][l]] = true; ck[l][a[i][a[j][l]]] = true; ck[l][a[j][a[i][l]]] = true; } } } while(q--) { cin >> pos1 >> pos2; if(ck[pos1][pos2]) { cout << "DA" << endl; } else { cout << "NE" << endl; } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...