# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
754605 | MilosMilutinovic | Pictionary (COCI18_pictionary) | C++14 | 95 ms | 12548 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;
const int N = 1e5 + 10;
vector<pair<int, int>> qs[N];
int n, m, q, fa[N], ans[N];
int gfa(int x) { return fa[x] == x ? x : fa[x] = gfa(fa[x]); }
void unite(int x, int y, int w) {
x = gfa(x);
y = gfa(y);
if (x == y) {
return;
}
if (qs[x].size() < qs[y].size()) {
swap(x, y);
}
for (auto& p : qs[y]) {
if (gfa(p.first) == x) {
ans[p.second] = w;
} else {
qs[x].push_back(p);
}
}
fa[y] = x;
}
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; i++) {
fa[i] = i;
}
for (int i = 1; i <= q; i++) {
int a, b;
scanf("%d%d", &a, &b);
qs[a].emplace_back(b, i);
qs[b].emplace_back(a, i);
}
for (int d = m; d >= 1; d--) {
vector<int> vec;
for (int i = d; i <= n; i += d) {
vec.push_back(i);
}
for (int i = 0; i + 1 < vec.size(); i++) {
unite(vec[i], vec[i + 1], m - d + 1);
}
}
for (int i = 1; i <= q; i++) {
printf("%d\n", ans[i]);
}
return 0;
}
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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |