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 nx=1e5+5;
int n, m, q, dsu[nx], l[nx], r[nx], res[nx], a[nx], b[nx];
vector<int> qrs[nx];
int find(int x)
{
if (x==dsu[x]) return x;
return dsu[x]=find(dsu[x]);
}
int main()
{
//cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>q;
for (int i=1; i<=q; i++) l[i]=1, r[i]=m, cin>>a[i]>>b[i];
while (1)
{
bool f=1;
for (int i=1; i<=m; i++) qrs[i].clear();
for (int i=1; i<=n; i++) dsu[i]=i;
for (int i=1; i<=q; i++) if (l[i]!=r[i]) f=0, qrs[(l[i]+r[i])/2].push_back(i);
//for (int i=1; i<=q; i++) cout<<i<<' '<<l[i]<<' '<<r[i]<<'\n';
if (f) break;
for (int i=1; i<=m; i++)
{
int g=m-i+1;
for (int j=2*g; j<=n; j+=g) dsu[find(j)]=find(g);
for (auto x:qrs[i])
{
if (find(a[x])==find(b[x])) r[x]=i;
else l[x]=i+1;
}
}
}
for (int i=1; i<=q; i++) cout<<l[i]<<'\n';
}
# | 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... |