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;
int num[500005];
vector<array<int, 2>> adj[100005];
set<int> C[100005];
int num_cnt = 0;
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int L, R, M;
cin >> L >> R >> M;
int i, j;
for(i=0;i<M;i++) {
int a, b;
cin >> a >> b;
adj[a-1].push_back({b-1, i});
}
for(i=0;i<L;i++) {
set<int> S;
for(auto n : adj[i]) {
bool isPos = false;
for(j=0;j<num_cnt;j++) {
if(S.find(j) == S.end() && C[j].find(n[0])==C[j].end()) {
num[n[1]] = j;
C[j].insert(n[0]);
S.insert(j);
isPos = true;
break;
}
}
if(!isPos) {
num[n[1]] = num_cnt;
C[num_cnt].insert(n[0]);
S.insert(num_cnt);
num_cnt++;
}
}
}
cout << num_cnt << '\n';
for(i=0;i<M;i++) cout << num[i] + 1 << '\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... |