AIZU ONLINE JUDGE Articulation Points Solution




Problem Link:  https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A 

 Solution in C++: 

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
const int MAX_NODE = 100009;
vector <int> graph[ MAX_NODE ];
int low[ MAX_NODE ], discover[ MAX_NODE ], visit[ MAX_NODE ], node, edge, discover_time;
int isArticulationPoint[ MAX_NODE ];
void ini()
{
    forint i = 0 ; i <= node ; i++ )
    {
        graph[i].clear();
        visit[i] = 0;
        isArticulationPoint[i] = 0;
    }
    discover_time = 1;
}
void constructGraph()
{
    cin >> node >> edge;
    ini();
    forint i = 0 ; i < edge ; i++ )
    {
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
}
void dfs( int node, int parnt )
{
    low[node] = discover[node] = discover_time++;
    visit[node] = 1;
    int sz = graph[node].size();
    int child = 0;
    forint i = 0 ; i < sz; i++ )
    {

        int nextNode = graph[node][i];
        if( parnt == nextNode ) continue;
        if( visit[nextNode] == 0 )
        {

            child++;
            dfs(nextNode, node );
            low[node] = min( low[node], low[nextNode]); // min value check with tree edge
            // root node condition
            if( parnt == -1 && child > 1 )
            {
                isArticulationPoint[node] = 1;

            }
            else if( parnt != -1 && low[nextNode] >= discover[node])
            {

                isArticulationPoint[node] = 1;
            }

        }
        else
        {

            low[node] = min( low[node], discover[nextNode] );// min value check with back edge
        }

    }
}
int main()
{
    constructGraph();
    forint i = 1 ; i < node ; i++ )
    {
        if( visit[i] == 0 ) dfs( i, -1 );
    }
    forint i = 0; i <node ; i++ )
    {
        if( isArticulationPoint[i] == 1 )
        {
            printf("%d\n",i);
        }
    }
}



No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.