-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
243 lines (208 loc) · 5.16 KB
/
B.cpp
File metadata and controls
243 lines (208 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/***********Template Starts Here***********/
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <functional>
#include <string>
#include <iostream>
#include <cctype>
#include <set>
#include <climits>
#include <iomanip>
#include <cassert>
#include <sstream>
#define pb push_back
#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))
using namespace std;
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < vlong, vlong > pll;
typedef vector<pll> vll;
typedef vector<vlong> vl;
const vlong inf = 2147383647;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-9;
struct debugger{
template<typename T> debugger& operator , (const T& v){
cerr<<v<<" ";
return *this;
}
}dbg;
inline vlong gcd ( vlong a, vlong b ) {
a = ABS ( a ); b = ABS ( b );
while ( b ) { a = a % b; swap ( a, b ); } return a;
}
vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
x2 = 1; y2 = 0;
x1 = 0; y1 = 1;
for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
q = r2 / r1;
r = r2 % r1;
x = x2 - (q * x1);
y = y2 - (q * y1);
}
*X = x2; *Y = y2;
return r2;
}
inline vlong modInv ( vlong a, vlong m ) {
vlong x, y;
ext_gcd( a, m, &x, &y );
x %= m;
if ( x < 0 ) x += m; //modInv is never negative
return x;
}
inline vlong power ( vlong a, vlong p ) {
vlong res = 1, x = a;
while ( p ) {
if ( p & 1 ) res = ( res * x );
x = ( x * x ); p >>= 1;
}
return res;
}
inline vlong bigmod ( vlong a, vlong p, vlong m ) {
vlong res = 1 % m, x = a % m;
while ( p ) {
if ( p & 1 ) res = ( res * x ) % m;
x = ( x * x ) % m; p >>= 1;
}
return res;
}
/***********Extended****************/
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scc(x,y) scanf("%d %d",&x,&y)
#define sccl(x,y) scanf("%lld %lld",&x,&y)
#define sccc(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define scccl(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define prc(c) printf("Case %d: ",c)
#define prn(c) printf("Case %d:\n",c)
#define pr(c) printf("%d\n",c)
#define prl(c) printf("%lld\n",c)
#define FORL(x,y,z) for(int x = y ; x<z ; x++)
#define FORE(x,y,z) for(int x = y ; x<=z; x++)
#define ROFE(x,y,z) for(int x = y ; x>=z; x--)
#define lli long long int
//int dx[] = {-1,1,0,0};
//int dy[] = {0,0,-1,1};
/***********Template Ends Here***********/
/*
int flag[50005];
int prime[50005];
int ind = 0;
void sieve(){
flag[0] = 1;
flag[1] = 1;
for(int i=4;i<=50000;i+=2) flag[i]++;
prime[0] = 2;
ind = 1;
for(int i=3;i<=50000;i+=2){
if(!flag[i]){
prime[ind] = i;
ind++;
for(int j=i+i;j<=50000;j+=i)
flag[j]++;
}
}
// cout<<prime[0]<<endl;
// cout<<prime[1]<<endl;
// cout<<prime[2]<<endl;
}
*/
/********************DONE***************/
vector<int>g[1050];
vector<int>nr[1050];
vector<int>spcl;
int spec[1050];
int connec[1050];
lli all[1050];
int p[1050];
int tata[1050];
int mat[1050][1050];
int findP(int u){
if(p[u]==u) return u;
p[u] = findP(p[u]);
return p[u];
}
void Union(int u,int v){
int pu = findP(u);
int pv = findP(v);
if(spec[pu]==1) p[pv] = p[pu];
else if(spec[pv]==1) p[pu] = p[pv];
else p[pv] = p[pu];
}
int main(){
int n,m,k;
int a;
sccc(n,m,k);
FORL(i,0,k){
sc(a);
spec[a] = 1;
connec[a] = a;
spcl.pb(a);
}
FORE(i,1,n) p[i]= i;
int u,v;
FORL(i,0,m){
scc(u,v);
g[u].pb(v);
g[v].pb(u);
mat[u][v] = 1;
mat[v][u] = 1;
Union(u,v);
}
//cout<<"yes"<<endl;
lli tt = 0;
lli ase = 0;
lli lagbe = 0;
FORE(i,1,n){
int p = findP(i);
tata[p]++;
all[p] += g[i].size();
if(spec[i]==0&&spec[p]==0){
tt ++;
ase += g[i].size();
}
}
//cout<<"yes"<<endl;
lagbe = (tt*(tt-1))/2 - ase/2;
lli mxxxx = 0;
FORL(i,0,spcl.size()){
int p = spcl[i];
lli tpp = tata[p] + tt;
//cout<<tpp<<" "<<tata[p]<<" "<<tt<<endl;
//cout<<ase<<" "<<all[p]<<endl;
lli tp = (tpp * (tpp-1))/2 - (all[p]/2 + ase/2);
if(mxxxx< tp) mxxxx = tp;
}
cout<<mxxxx<<endl;
}