Submission #6068916
Source Code Expand
Copy
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; struct UnionFind{ vector<int> par; UnionFind(int n):par(n,-1){} int find(int x){ if(par[x]<0)return x; return par[x]=find(par[x]); } bool unite(int x,int y){ x=find(x); y=find(y); if(x==y)return false; if(par[x]>par[y]){ par[y]+=par[x]; par[x]=y; } else{ par[x]+=par[y]; par[y]=x; } return true; } bool same(int x,int y){ return find(x)==find(y); } int size(int x){ return -par[find(x)]; } }; int main(){ int n; cin>>n; UnionFind uf(202020); rep(i,n){ int x,y; cin>>x>>y; uf.unite(x,y+101010); } vector<ll> a(202020),b(202020); rep(i,101010){ a[uf.find(i)]++; b[uf.find(i+101010)]++; } ll ans = 0; rep(i,202020)ans += a[i]*b[i]; cout<<ans-n<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Must Be Rectangular! |
User | tempura0224 |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1459 Byte |
Status | AC |
Exec Time | 62 ms |
Memory | 4224 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
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 | 3 ms | 4224 KB |
02.txt | AC | 3 ms | 4224 KB |
03.txt | AC | 3 ms | 4224 KB |
04.txt | AC | 3 ms | 4224 KB |
05.txt | AC | 3 ms | 4224 KB |
06.txt | AC | 4 ms | 4224 KB |
07.txt | AC | 4 ms | 4224 KB |
08.txt | AC | 4 ms | 4224 KB |
09.txt | AC | 62 ms | 4224 KB |
10.txt | AC | 62 ms | 4224 KB |
11.txt | AC | 62 ms | 4224 KB |
12.txt | AC | 62 ms | 4224 KB |
13.txt | AC | 62 ms | 4224 KB |
14.txt | AC | 62 ms | 4224 KB |
15.txt | AC | 62 ms | 4224 KB |
16.txt | AC | 62 ms | 4224 KB |
17.txt | AC | 60 ms | 4224 KB |
s1.txt | AC | 3 ms | 4224 KB |
s2.txt | AC | 3 ms | 4224 KB |
s3.txt | AC | 3 ms | 4224 KB |