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 = 1e2 + 7;
int l, r, m;
vector<pair<int, int>> e;
map<pair<int, int>, int> cols;
bool check(int x)
{
map<int, int> chs[x + 1];
for (auto u : e)
{
bool ok = 0;
for (int j = 0; j < x; j++)
{
if (!(chs[j][u.first] | chs[j][u.second]))
{
ok = 1;
cols[u] = j + 1;
chs[j][u.first] = chs[j][u.second] = 1;
break;
}
}
if (!ok)
return 0;
}
return 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();
//freopen("in.in", "r", stdin);
cin >> l >> r >> m;
for (int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
v += l;
e.push_back({u, v});
}
int lo = 1, hi = m;
int ans = 0;
for (; lo <= hi;)
{
int mid = (lo + hi) >> 1;
if (check(mid))
{
ans = mid;
hi = mid - 1;
}
else
{
lo = mid + 1;
}
}
cout << ans << '\n';
for (auto u : e)
{
cout << cols[u] << "\n";
}
return 0;
}
# | 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... |