-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
50 lines (47 loc) · 943 Bytes
/
B.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
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
int ara[150][150];
int main()
{
fastio;
int n,m,u,v,i,j,p,cnt=0,x,idx;
cin>>n>>m;
for(i=0;i<m;i++)
{
cin>>u>>v;
ara[u-1][v-1]=1;
ara[v-1][u-1]=1;
}
while(true)
{
vector<pair<int,int> > vect;
p=0;
for(i=0;i<n;i++)
{
x=0;
for(j=0;j<n;j++)
{
if(ara[i][j]==1)
{
x++;
idx=j;
}
}
if(x==1)
{
p=1;
ara[i][idx]=0;
vect.push_back({idx,i});
}
}
if(p==1)
cnt++;
else
break;
for(i=0;i<vect.size();i++)
ara[vect[i].first][vect[i].second]=0;
}
cout<<cnt<<"\n";
return 0;
}