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];
array<int, 2> Edge[100005];
vector<int> adj[100005];
vector<int> adj2[100005];
int num_cnt = 0;
int num1[100005];
int num2[100005];
bool pos[10005][10005];
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);
adj2[b-1].push_back(a-1);
Edge[i] = {a-1, b-1};
}
for(i=0;i<=L;i++) {
for(j=0;j<=10000;j++) pos[i][j] = true;
}
for(i=0;i<L;i++) {
int cnt = 0;
while(!pos[i][cnt]) cnt++;
pos[i][cnt] = 0;
num1[i] = cnt;
for(int j : adj[i]) {
for(int k : adj2[j]) pos[k][cnt] = false;
}
}
for(i=0;i<=R;i++) {
for(j=0;j<=10000;j++) pos[i][j] = true;
}
for(j=0;j<R;j++) {
int cnt = 0;
while(!pos[j][cnt]) cnt++;
pos[j][cnt] = true;
num2[j] = cnt;
for(int i : adj2[j]) {
for(int k : adj[i]) pos[k][cnt] = false;
}
}
vector<int> idx;
for(i=0;i<M;i++) {
idx.push_back(num1[Edge[i][0]]^num2[Edge[i][1]]);
num[i] = num1[Edge[i][0]]^num2[Edge[i][1]];
}
sort(idx.begin(),idx.end());
idx.erase(unique(idx.begin(),idx.end()),idx.end());
for(i=0;i<M;i++) {
num[i] = lower_bound(idx.begin(),idx.end(),num[i]) - idx.begin();
}
cout << idx.size() << '\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... |