forked from Masked-coder11/gfg-POTD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16.05.2024.cpp
40 lines (31 loc) · 807 Bytes
/
16.05.2024.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
class Solution {
public:
int ans=0;
int dfs(vector<int>adj[], vector<int>&vis, int start){
vis[start]=1;
int cnt=0;
for(auto it:adj[start]){
if(!vis[it]){
int res=dfs(adj, vis, it);
if(res%2==0){
ans++;
}
else{
cnt+=res;
}
}
}
return cnt+1;
}
int minimumEdgeRemove(int n, vector<vector<int>>edges){
// Code here
vector<int>adj[n];
for(int i=0;i<edges.size();i++){
adj[edges[i][0]-1].push_back(edges[i][1]-1);
adj[edges[i][1]-1].push_back(edges[i][0]-1);
}
vector<int>vis(n,0);
dfs(adj, vis, 0);
return ans;
}
};