Submission #818984

#TimeUsernameProblemLanguageResultExecution timeMemory
818984Sandarach151Kutije (COCI21_kutije)C++17
70 / 70
934 ms14988 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, q; cin >> n >> m >> q; vector<int> adg[n]; for(int i=0; i<m; i++){ for(int j=0; j<n; j++){ int a; cin >> a; a--; adg[a].push_back(j); } } bool reach[n][n]; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ reach[i][j]=0; } } for(int i=0; i<n; i++){ queue<int> que; que.push(i); reach[i][i]=true; while(!que.empty()){ int cur = que.front(); que.pop(); for(auto u : adg[cur]){ if(!reach[i][u]){ reach[i][u]=true; que.push(u); } } } } // for(int i=0; i<n; i++){ // cout << i << ": "; // for(auto u : adg[i]){ // cout << u; // } // cout << '\n'; // } for(int query=0; query<q; query++){ int a, b; cin >> a >> b; a--; b--; if(reach[a][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...