이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |