-
Notifications
You must be signed in to change notification settings - Fork 1
/
kennedy-space-centre.cpp
99 lines (78 loc) · 1.59 KB
/
kennedy-space-centre.cpp
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
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
typedef long long Int;
typedef unsigned long long UInt;
typedef vector <int> VI;
typedef pair <int, int> PII;
VI a[1<<17];
bool was[1<<17];
int n,m;
int dfs(int cur)
{
if (was[cur])
return 0;
was[cur] = true;
int res = 1;
REP(i,SZ(a[cur]))
{
int nx = a[cur][i];
res += dfs(nx);
}
return res;
}
int main()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d%d",&n,&m);
REP(i,m)
{
int x,y;
scanf("%d%d",&x,&y);
a[x].push_back(y);
a[y].push_back(x);
}
VI all;
REP(i,n)
{
if (!was[i])
{
all.push_back(dfs(i));
}
}
Int res = 0;
Int sum = 0;
REP(i, SZ(all))
{
res += sum * all[i];
sum += all[i];
}
cout << res << endl;
return 0;
}