Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define x first
- #define y second
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int N;
- cin >> N;
- vector<pair<int,int>> a(N);
- for(auto &x : a)
- cin >> x.x >> x.y;
- vector<bool> mark(N);
- int ans = 0, erased = 0;
- while(erased < N) {
- ++ans;
- vector<int> cntX(N + 1), cntY(N + 1);
- int mx = 0, type = 1, v = 0;
- for(int i = 0; i < N; ++i)
- if(!mark[i]) {
- ++cntX[a[i].x], ++cntY[a[i].y];
- if(cntX[a[i].x] > mx) {
- mx = cntX[a[i].x];
- type = 1;
- v = a[i].x;
- }
- if(cntY[a[i].y] > mx) {
- mx = cntY[a[i].y];
- type = 0;
- v = a[i].y;
- }
- }
- if(type == 1) {
- for(int i = 0; i < N; ++i)
- if(!mark[i] && a[i].x == v) {
- mark[i] = true;
- ++erased;
- }
- }
- else
- for(int i = 0; i < N; ++i)
- if(!mark[i] && a[i].y == v) {
- mark[i] = true;
- ++erased;
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement