-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudents Problem ans.cpp
More file actions
74 lines (65 loc) · 1.46 KB
/
Students Problem ans.cpp
File metadata and controls
74 lines (65 loc) · 1.46 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
#include<bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
#define N 10000000
#define limit 10000
template <typename T>
void print(T x){cout<<x<<"\n";}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<"\n";}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<"\n";}
vector<int> node[N+1];
bool vis[N+1];
int outdegree;
void dfs(int child)
{
vis[child]=true;
int p=node[child].size();
if(p==0)
p=1;
outdegree=max(outdegree,p);
for(auto x: node[child])
if(!vis[x])
dfs(x);
}
signed main()
{
io;
int test_case;
//cin>>test_case;
test_case=1;
while(test_case--)
{
int n,m;
cin>>n>>m;
map<pair<int,int>,int> store;
int cnt=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
store[{i+1,j+1}]=cnt;
cnt++;
}
}
int a,b,c,d;
for(int i=0;i<m;i++)
{
cin>>a>>b>>c>>d;
node[store[{a,b}]].push_back(store[{c,d}]);
node[store[{c,d}]].push_back(store[{a,b}]);
}
int ans=0;
outdegree=0;
for(int i=1;i<=n*n;i++)
{
if(!vis[i])
dfs(i);
ans+=outdegree;
outdegree=0;
}
print(ans);
}
}