| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 528348 | ivls | Kutije (COCI21_kutije) | C++17 | 175 ms | 9400 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct dsu
{
int n, p[1010];
void init(int nn)
{
n = nn;
for (int i = 1; i <= n; i++) p[i] = i;
}
int get(int v) { return v == p[v] ? v : p[v] = get(p[v]); }
bool same(int u, int v) { return get(u) == get(v); }
void uni(int u, int v) { u = get(u); v = get(v); p[u] = v; }
};
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
int p[n + 1];
dsu d;
d.init(n);
while (m--)
for (int i = 1; i <= n; i++) { int v; cin >> v; d.uni(i, v); }
while (q--)
{
int a, b;
cin >> a >> b;
cout << (d.same(a, b) ? "DA" : "NE") << '\n';
}
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
