Submission #507670

#TimeUsernameProblemLanguageResultExecution timeMemory
507670penguinhackerKutije (COCI21_kutije)C++14
70 / 70
156 ms10204 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=1000; int n, m, q, cmp[mxN], c; bool adj[mxN][mxN]; void dfs(int u) { cmp[u]=c; for (int v=0; v<n; ++v) if (adj[u][v]&&!cmp[v]) dfs(v); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> q; for (int i=0; i<m; ++i) for (int j=0; j<n; ++j) { int k; cin >> k, --k; adj[j][k]=adj[k][j]=1; } for (int i=0; i<n; ++i) if (!cmp[i]) ++c, dfs(i); while(q--) { int u, v; cin >> u >> v, --u, --v; cout << (cmp[u]==cmp[v]?"DA":"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...