제출 #699486

#제출 시각아이디문제언어결과실행 시간메모리
699486Cross_RatioTeoretičar (COCI18_teoreticar)C++14
13 / 130
271 ms31328 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...