1. In given graph Cities are vertices and subway are edges.Graph is undirected as we can go A to B and can also come back. Unweighted graph.
2. Even after removing a edge if a graph is connected then the edge is not critical otherwise it is critical edge.
Tarjan algorithm for finding bridge . This algorithm mainly maintains two array dis[ ] and low[ ]. dis array mainly contain number of dfs call we needed to get to this node and low contains smallest number of call to reach a vertex which is connected to our vertices . If u,v is connected and u is parent of vand low[v]>dis[u] then u,v is a bridge.
int dfs(int i)
{
static int time=0;
int cou_o_children=0; // count of children
vis[i]=true; dis[u]=low[u]=++time; // make current node as visited and intialise time to get to that node and minimum time to get to that node
for(auto k=v1[i].begin();k!=v1[i].end();k++)
{
if(vis[*k]==0)
{
par[*k]=i; dfs(*k);
low[i] = min(low[i], low[*k]); // check subtree rooted at *k has connection with one of ancestor of i
if (low[*k] > disc[i]) // it means *k and i is critical subway.
}
else if (*k != parent[i]) // update low value for i
low[i] = min(low[i], disc[*k]);
}
}
3. Critical edge are also called bridge edge . Time complexity of most efficient algorithm is O(V+E) using adjacency lists. Basically in this algorithm we are doing dfs . In DFS tree an edge (u, v) is bridge if there is no way to reach u or an ancestor of u from subtree rooted with v if we remove edge between (u,v).
Problem 5: Aging Infrastructure [20 points Around the United States, subway systems that were built decades...