Submission #6068700


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
const int Maxn=100005,maxi=100000;
int fa[2*Maxn],cnt[2*Maxn];
int get_fa(int x)
{
	return x==fa[x]?fa[x]:fa[x]=get_fa(fa[x]);
}
void merge(int x,int y)
{
	int a=get_fa(x),b=get_fa(y);
	cnt[b]+=cnt[a];
	fa[a]=b;
}
int n;
long long tot,ans[2*Maxn][3];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*maxi;i++)
		fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y+maxi);
		cnt[get_fa(x)]++;
	}
	for(int i=1;i<=maxi;i++)
		ans[get_fa(i)][1]++;
	for(int i=maxi+1;i<=2*maxi;i++)
		ans[get_fa(i)][2]++;
	for(int i=1;i<=2*maxi;i++)
		if(get_fa(i)==i) tot+=(ans[i][1]*ans[i][2]-cnt[i]);
	printf("%lld",tot);
	return 0;
}

Submission Info

Submission Time
Task F - Must Be Rectangular!
User sys
Language C++14 (GCC 5.4.1)
Score 0
Code Size 724 Byte
Status WA
Exec Time 27 ms
Memory 6528 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:19:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 14
WA × 6
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 4 ms 6528 KB
02.txt AC 4 ms 6528 KB
03.txt AC 4 ms 6528 KB
04.txt AC 4 ms 6528 KB
05.txt AC 4 ms 6528 KB
06.txt AC 4 ms 6528 KB
07.txt WA 4 ms 6528 KB
08.txt WA 4 ms 6528 KB
09.txt AC 26 ms 6528 KB
10.txt AC 27 ms 6528 KB
11.txt AC 27 ms 6528 KB
12.txt AC 27 ms 6528 KB
13.txt AC 27 ms 6528 KB
14.txt WA 27 ms 6528 KB
15.txt WA 27 ms 6528 KB
16.txt WA 27 ms 6528 KB
17.txt WA 21 ms 6528 KB
s1.txt AC 4 ms 6528 KB
s2.txt AC 4 ms 6528 KB
s3.txt AC 4 ms 6528 KB