이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int num[500005];
vector<array<int, 2>> adj[100005];
set<int> C[100005];
int num_cnt = 0;
array<int, 2> Edge[500005];
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});
Edge[i] = {a-1, b-1};
}
if(M <= 200000) {
vector<int> V;
for(i=0;i<L;i++) V.push_back(i);
sort(V.begin(),V.end(),[&](int x, int y) {
return adj[x].size()>adj[y].size();
});
for(int i : V) {
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';
return 0;
}
vector<int> idx;
for(i=0;i<M;i++) {
idx.push_back(Edge[i][0]^Edge[i][1]);
num[i] = Edge[i][0]^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... |