#include <bits/stdc++.h>
#define pii pair<int,int>
#define ft first
#define sd second
#define MP make_pair
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 5010;
const int M = 500100;
const int oo = 2e9;
int col[M], l, r, mrk[2][N][N], m, ans = oo, nm[M], mem[M], x[M], y[M];
mt19937 rnd(chrono::system_clock().now().time_since_epoch().count());
void potential(){
shuffle(nm, nm + m, rnd);
int cur = 0;
for (int i = 0; i < max(l, r); i++)
for (int j = 0; j < max(l, r); j++)
mrk[0][i][j] = mrk[1][i][j] = 0;
for (int it = 0; it < m; it++){
int i = nm[it];
for (int c = 0; ; c++)
if (!mrk[0][x[i]][c] && !mrk[1][y[i]][c]){
col[i] = c;
cur = max(cur, c);
mrk[0][x[i]][c] = mrk[1][y[i]][c] = 1;
break;
}
}
if (ans > cur){
ans = cur;
for (int i = 0; i < m; i++)
mem[i] = col[i];
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> l >> r >> m;
for (int i = 0; i < m; i++){
cin >> x[i] >> y[i];
x[i]--; y[i]--;
nm[i] = i;
}
for (int it = 0; it < 500; it++)
potential();
cout << ans + 1 << '\n';
for (int i = 0; i < m; i++)
cout << mem[i] + 1 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
512 KB |
too many colors |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1280 KB |
Output is correct |
2 |
Correct |
12 ms |
1280 KB |
Output is correct |
3 |
Correct |
11 ms |
1280 KB |
Output is correct |
4 |
Incorrect |
7 ms |
896 KB |
too many colors |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4902 ms |
95036 KB |
too many colors |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5173 ms |
95096 KB |
Output is correct |
2 |
Correct |
750 ms |
16508 KB |
Output is correct |
3 |
Correct |
11886 ms |
196620 KB |
Output is correct |
4 |
Incorrect |
314 ms |
8184 KB |
too many colors |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
816 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
797 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
847 ms |
262144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
12100 ms |
35368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
12077 ms |
170968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
12018 ms |
171516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |