Submission #504137

#TimeUsernameProblemLanguageResultExecution timeMemory
504137kojacKutije (COCI21_kutije)C++17
20 / 70
1039 ms6684 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 1020 #define INF 999999999 #define ll long long #define F first #define S second #define endl "\n" int n, m, q, lista[MAXN][MAXN], c[MAXN][MAXN]; bool foi[MAXN]; void dfs(int x){ for(int i = 1; i < MAXN; i++){ if(lista[x][i] == 1 && !foi[i]){ foi[i] = true; dfs(i); } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> q; for(int i = 0; i < m; i++){ for(int j = 1; j <= n; j++){ int x; cin >> x; lista[j][x] = 1; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++) foi[j] = false; foi[i] = true; dfs(i); for(int j = 1; j <= n; j++){ if(foi[j]){ c[i][j] = 1; } } } for(int i = 0; i < q; i++){ int a, b; for(int j = 0; j < MAXN; j++) foi[j] = false; cin >> a >> b; foi[a] = true; dfs(a); if(c[a][b] == 1) cout << "DA\n"; else cout << "NE\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...