Submission #537886

#TimeUsernameProblemLanguageResultExecution timeMemory
537886davi_bartKutije (COCI21_kutije)C++14
70 / 70
151 ms9404 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define fi first #define se second #define ld long double #define pb push_back mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int N, M, Q; vector<int> v[1010]; struct dsu { int par[1010]; void init() { iota(par, par + 1005, 0); } int p(int pos) { return par[pos] = (pos == par[pos] ? pos : p(par[pos])); } void unite(int a, int b) { a = p(a); b = p(b); if (a == b) return; par[a] = b; } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M >> Q; dsu d; d.init(); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { int x; cin >> x; x--; d.unite(x, j); } } for (int i = 0; i < Q; i++) { int a, b; cin >> a >> b; a--; b--; if (d.p(a) == d.p(b)) 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...