Submission #699476

#TimeUsernameProblemLanguageResultExecution timeMemory
699476Cross_RatioTeoretičar (COCI18_teoreticar)C++14
26 / 130
12060 ms46988 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; 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}); } 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'; }
#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...