#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=2e5+99;
int n,t,w[N];
pair<int,int> a[N];
vector<int> g[N];
map<pair<int,int>,int> edge,mark;
ll ans;
void Add_edge(int u,int v){
if(edge[mp(u,v)]) return ;
g[u].pb(v);
g[v].pb(u);
edge[mp(u,v)]=1;
edge[mp(v,u)]=1;
}
void dfs(int x,int par){
f(i,0,g[x].size()){
if(g[x][i]!=par){
dfs(g[x][i],x);
w[x]+=w[g[x][i]];
}
}
ans+=1ll*w[x]*(n-w[x]);
}
void solve(){
f(i,0,N) g[i].clear();
fill(w,w+N,0);
mark.clear();
edge.clear();
sort(a,a+n);
int cnt=1;
f(i,0,n){
mark[mp(a[i].F,a[i].S)]=mark[mp(a[i].F-1,a[i].S)];
if(!mark[mp(a[i].F,a[i].S)]){
mark[mp(a[i].F,a[i].S)]=cnt++;
}
w[mark[mp(a[i].F,a[i].S)]]++;
}
f(i,0,n){
if(mark[mp(a[i].F,a[i].S+1)]){
Add_edge(mark[mp(a[i].F,a[i].S)],mark[mp(a[i].F,a[i].S+1)]);
}
}
dfs(1,0);
}
int DistanceSum(int N, int *X, int *Y){
n=N;
f(i,0,n) a[i].F=X[i],a[i].S=Y[i];
solve();
f(i,0,n) a[i].F=Y[i],a[i].S=X[i];
solve();
return ans;
}
/*
2,5
v = (2, 6), v = (3, 3), v = (3, 6), v = (4, 3), v = (4, 4), v = (4, 5), v = (4, 6), v = (5, 3), v = (5,
4), and v = (5, 6)
11
2 5
2 6
3 3
3 6
4 3
4 4
4 5
4 6
5 3
5 4
5 6
*/
Compilation message
city.cpp: In function 'void dfs(int, int)':
city.cpp:7:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | #define f(i,a,b) for(int i=a;i<b;i++)
......
36 | f(i,0,g[x].size()){
| ~~~~~~~~~~~~~~~
city.cpp:36:2: note: in expansion of macro 'f'
36 | f(i,0,g[x].size()){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5712 KB |
Output is correct |
2 |
Correct |
3 ms |
5712 KB |
Output is correct |
3 |
Correct |
5 ms |
5712 KB |
Output is correct |
4 |
Correct |
4 ms |
5712 KB |
Output is correct |
5 |
Correct |
4 ms |
5712 KB |
Output is correct |
6 |
Correct |
4 ms |
5840 KB |
Output is correct |
7 |
Correct |
6 ms |
5712 KB |
Output is correct |
8 |
Correct |
5 ms |
5712 KB |
Output is correct |
9 |
Correct |
4 ms |
5712 KB |
Output is correct |
10 |
Correct |
5 ms |
5712 KB |
Output is correct |
11 |
Correct |
4 ms |
5712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5968 KB |
Output is correct |
2 |
Correct |
5 ms |
5840 KB |
Output is correct |
3 |
Correct |
6 ms |
5968 KB |
Output is correct |
4 |
Correct |
6 ms |
5916 KB |
Output is correct |
5 |
Correct |
6 ms |
6120 KB |
Output is correct |
6 |
Correct |
6 ms |
5968 KB |
Output is correct |
7 |
Correct |
7 ms |
6096 KB |
Output is correct |
8 |
Correct |
7 ms |
5968 KB |
Output is correct |
9 |
Correct |
6 ms |
5968 KB |
Output is correct |
10 |
Correct |
6 ms |
5936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
7560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
9588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |