# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
87379 | mirbek01 | Pictionary (COCI18_pictionary) | C++17 | 1580 ms | 28408 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 + 2;
int n, m, q, ans[N], p[N], sz[N];
vector < pair <int, int> > v[N];
vector < tuple <int, int, int> > vec;
int get(int v){
return (p[v] == v) ? v : p[v] = get(p[v]);
}
void unite(int a, int b){
a = get(a);
b = get(b);
if(a != b){
if(sz[a] < sz[b])
swap(a, b);
p[b] = a;
sz[a] += sz[b];
}
}
int main(){
scanf("%d %d %d", &n, &m, &q);
for(int i = 1; i <= n; i ++)
p[i] = i, sz[i] = 1;
for(int i = 1; i <= m; i ++){
for(int j = i; j <= n; j += i){
v[__gcd(i, j)].push_back({i, j});
}
}
for(int i = 1; i <= q; i ++){
int u, v;
cin >> u >> v;
vec.push_back(make_tuple(u, v, i));
}
for(int i = m; i >= 1; i --){
for(int j = 0; j < v[i].size(); j ++){
int a = v[i][j].first, b = v[i][j].second;
unite(a, b);
}
for(int j = 0; j < vec.size(); j ++){
int a = get<0>(vec[j]);
int b = get<1>(vec[j]);
int c = get<2>(vec[j]);
if(!ans[c]){
if(get(a) == get(b)){
ans[c] = i;
}
}
}
}
for(int i = 1; i <= q; i ++)
cout << m - ans[i] + 1 << endl;
}
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... |