Submission #6068386


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int mn=2e5+10;
vector<int>ix[mn],iy[mn];
int x[mn],y[mn];
bool vis[mn];
ll tot;
set<int>sx,sy;
void dfs(int n){
    vis[n]=1;
    sx.insert(x[n]);
    sy.insert(y[n]);
    for(int k:ix[x[n]])if(!vis[k])dfs(k);
    for(int k:iy[y[n]])if(!vis[k])dfs(k);
}
int main(){
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",x+i,y+i);
        ix[x[i]].push_back(i);
        iy[y[i]].push_back(i);
    }
    for(i=0;i<n;i++){
        if(!vis[i]){
            dfs(i);
            tot+=sx.size()*sy.size();
            sx.clear();
            sy.clear();
        }
    }
    printf("%lld",tot-n);
}

Submission Info

Submission Time
Task F - Must Be Rectangular!
User KevinWan
Language C++14 (GCC 5.4.1)
Score 600
Code Size 744 Byte
Status AC
Exec Time 109 ms
Memory 21376 KB

Compile Error

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

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 9600 KB
02.txt AC 5 ms 9600 KB
03.txt AC 5 ms 9600 KB
04.txt AC 5 ms 9600 KB
05.txt AC 5 ms 9600 KB
06.txt AC 5 ms 9728 KB
07.txt AC 5 ms 9728 KB
08.txt AC 5 ms 9728 KB
09.txt AC 109 ms 21376 KB
10.txt AC 101 ms 18432 KB
11.txt AC 100 ms 18432 KB
12.txt AC 79 ms 14080 KB
13.txt AC 79 ms 14080 KB
14.txt AC 97 ms 18176 KB
15.txt AC 97 ms 18176 KB
16.txt AC 96 ms 18048 KB
17.txt AC 95 ms 14592 KB
s1.txt AC 5 ms 9600 KB
s2.txt AC 5 ms 9600 KB
s3.txt AC 5 ms 9600 KB