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

Submission #6068092

Source Code Expand

Copy
```#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v),v.end()))
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define dbg(x);
#define dbgv(v);
#define y1 EsiHancagorcRepa
#ifdef ALEXPC
#define dbg(x); cout<<#x<<" = "<<x<<endl
#define dbgv(v); cout<<#v<<" = ["; trav(tv,v)cout<<"tv,";cout<<"]"<<endl
#endif

//const int N=100,M=N*N;
const ll MOD=1000*1000*1000+7;

const int N=1e5+6;

vector<int> g[2*N];
ll qan1[2*N],qan2[2*N];
bool col[2*N];
void dfs(int v,int comp){
if (v>N) qan1[comp]++;
else qan2[comp]++;
col[v]=true;
trav(to,g[v]){
if (!col[to])dfs(to,comp);
}
}

int main(){
fastio;
srng;
int m;
cin>>m;
FOR(i,m){
int a,b;
cin>>a>>b;
a+=N;
g[a].push_back(b);
g[b].push_back(a);
}
int cmp=1;
ll ans=0;
FOR(i,2*N){
if (!col[i]){
dfs(i,cmp);
ans+=qan1[cmp]*qan2[cmp];
cmp++;
}
}
cout<<ans-m<<endl;
return 0;
}
```

#### Submission Info

Submission Time 2019-06-22 21:40:13+0900 F - Must Be Rectangular! Abelyan C++14 (GCC 5.4.1) 600 1676 Byte AC 42 ms 13056 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 5 ms 7168 KB
02.txt AC 5 ms 7168 KB
03.txt AC 5 ms 7168 KB
04.txt AC 5 ms 7168 KB
05.txt AC 5 ms 7168 KB
06.txt AC 5 ms 7424 KB
07.txt AC 5 ms 7424 KB
08.txt AC 5 ms 7424 KB
09.txt AC 42 ms 13056 KB
10.txt AC 40 ms 11648 KB
11.txt AC 40 ms 9984 KB
12.txt AC 42 ms 9984 KB
13.txt AC 40 ms 9984 KB
14.txt AC 40 ms 10112 KB
15.txt AC 40 ms 10112 KB
16.txt AC 40 ms 10112 KB
17.txt AC 21 ms 8192 KB
s1.txt AC 5 ms 7168 KB
s2.txt AC 5 ms 7168 KB
s3.txt AC 5 ms 7168 KB