Contest Duration: - (local time) (100 minutes) Back to Home

Submission #6072845

Source Code Expand

Copy
```#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

struct UFT{    //O(loga(n))
int n;
vi d, r;
UFT(int n) : n(n), d(n, -1), r(n, 0){};
int root(int i){
if(d[i] < 0) return i;
return d[i] = root(d[i]);
}
bool same(int x, int y){
return root(x) == root(y);
}
bool unite(int x, int y){
x = root(x);
y = root(y);
if(x == y) return false;

if(r[x] < r[y]) swap(x, y);
else if(r[x] == r[y]) r[x]++;
d[x] += d[y];
d[y] = x;
return true;
}
int size(int i){
return -d[root(i)];
}
};

int main(){
int n;
cin >> n;
vector<int> x(n), y(n);
map<int, int> mx, my;

UFT uf(n);

rep(i, n) {
cin >> x[i] >> y[i];
if(mx.count(x[i])) {
uf.unite(i, mx[x[i]]);
}
else mx[x[i]] = i;
if(my.count(y[i])) {
uf.unite(i, my[y[i]]);
}
else my[y[i]] = i;
}

ll ans = 0LL;
vector<vector<int>> v(n);
rep(i, n) {
v[uf.root(i)].pb(i);
}

for(auto&& g : v) {
if(g.size() == 1) continue;
set<int> sx, sy;
for(auto&& i : g) {
sx.insert(x[i]);
sy.insert(y[i]);
}
ll sz_x = sx.size();
ll sz_y = sy.size();
if(sz_x == 1 || sz_y == 1) continue;
ans += sz_x * sz_y;
ans -= g.size();
}
cout << ans << '\n';
return 0;
}```

Submission Info

Submission Time 2019-06-22 21:59:49+0900 F - Must Be Rectangular! T1610 C++14 (GCC 5.4.1) 600 2045 Byte AC 196 ms 13944 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
 AC × 3
 AC × 20
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 2 ms 384 KB
07.txt AC 2 ms 384 KB
08.txt AC 2 ms 384 KB
09.txt AC 194 ms 13944 KB
10.txt AC 195 ms 13944 KB
11.txt AC 196 ms 13944 KB
12.txt AC 174 ms 9728 KB
13.txt AC 170 ms 9728 KB
14.txt AC 189 ms 13584 KB
15.txt AC 189 ms 13580 KB
16.txt AC 187 ms 13460 KB
17.txt AC 90 ms 4864 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB