File tree Expand file tree Collapse file tree 1 file changed +74
-0
lines changed
Expand file tree Collapse file tree 1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ #define fastio ios_base::sync_with_stdio (false );cin.tie(NULL );cout<<fixed;cout.precision(10 );
3+ #define endl " \n "
4+ #define tc ll T; cin >> T; while (T--)
5+ #define pb push_back
6+ #define mod 1000000007
7+ #define S second
8+ #define F first
9+ using namespace std ;
10+ typedef long long ll;
11+ const int N = 1e4 +5 ;
12+
13+ int n, m, inTm, ans;
14+ vector<int > adj[N], vis(N);
15+ vector<int > low (N), par(N), inTime(N), ap(N);
16+
17+ void articulationP (int s){
18+
19+ int cnt = 0 ;
20+ vis[s] = 1 ;
21+ inTime[s] = low[s] = ++inTm;
22+
23+ for (auto i : adj[s]){
24+
25+ if (!vis[i]){
26+ cnt++;
27+ par[i] = s;
28+ articulationP (i);
29+ low[s] = min (low[s], low[i]);
30+
31+ if (par[s] == -1 and cnt > 1 ) ap[s] = 1 ;
32+ if (par[s] != -1 and low[i] >= inTime[s]) ap[s] = 1 ;
33+ }
34+ else if (i != par[s]) low[s] = min (low[s], inTime[i]);
35+ }
36+
37+ }
38+
39+ int main (){
40+
41+ fastio;
42+ while (1 ){
43+ cin >> n >> m;
44+ if (n == 0 and m == 0 ) break ;
45+ int a, b;
46+ ans = inTm = 0 ;
47+ vis.clear (); vis.resize (N);
48+ low.clear (); low.resize (N);
49+ par.clear (); par.resize (N, -1 );
50+ ap.clear (); ap.resize (N);
51+ inTime.clear (); inTime.resize (N);
52+ for (int i = 0 ; i < N; i++) adj[i].clear ();
53+
54+ for (int i = 0 ; i < m; i++){
55+ cin >> a >> b;
56+ adj[a].pb (b);
57+ adj[b].pb (a);
58+ }
59+ for (int i = 1 ; i <= n; i++){
60+ if (!vis[i]){
61+ articulationP (i);
62+ }
63+ }
64+
65+ for (int i = 1 ; i <= n; i++)
66+ ans += ap[i];
67+ cout << ans << endl;
68+
69+
70+ }
71+
72+ return 0 ;
73+
74+ }
You can’t perform that action at this time.
0 commit comments