-
Notifications
You must be signed in to change notification settings - Fork 0
/
codepur.cpp
107 lines (88 loc) · 1.45 KB
/
codepur.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
100
101
102
103
104
/**
*
* @Author : Vinay Kushwaha (iamvinayvk)
*
* @DateTime : 12/24/2020 11:06:41 PM
*
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define w(t) int t;cin>>t;while(t--)
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define vi vector<int>
#define vll vector<long long>
#define FOR(start,end,increment) for(ll i=start;i<end;i+=increment)
ll gcd(ll a, ll b)
{
if(a==0)
return b;
return gcd(b%a,a);
}
vector<vector<int>> g(1e5+1);
vector<int> visited(1e5+1),tin(1e5+1),low(1e5+1);
bool bridge=false;
int t=0;
vector<pair<int,int>> edgeList;
void dfs(int v,int parent)
{
visited[v]=1;
tin[v]=low[v]=++t;
for(auto child:g[v])
{
if(child==parent)
continue;
if(visited[child])
{
low[v]=min(low[v],tin[child]);
}
else
{
dfs(child,v);
if(low[child]>tin[v])
{
bridge=true;
return;
}
else
{
// edgeList.push_back(make_pair(child,v));
low[v]=min(low[v],low[child]);
}
}
}
}
int main(){
fast
ll n,m;
cin>>n>>m;
for(int i=0;i<m;i++)
{
int u,v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
ll cc=0;
for(int i=1;i<=n;i++)
{
if(visited[i]==0)
{
dfs(i,-1);
cc++;
// cout<<"i:"<<i<<"\n";
}
}
cout<<cc<<" "<<bridge<<"\n";
if(bridge||cc>1)
cout<<"YES\n";
else
{
cout<<"NO\n";
}
return 0;
}