0

Cities are connected by telephone wires and communicating. I want destroy all cities but not alarm another too early, so i disconnect wire before destroying town. I don't want disconnect town what is used as bridge between two cities.

It is Undirected graph if I'm not mistaken. But I do not get it how i can check what cities i can remove and what not. I looked at Tarjan's Algorithm but it i don't get it.

This is test input:

15 19 <- Number of cities and number of connections
1 2 <- Start of connections list
2 3
2 4
2 5
5 6
5 7
7 8
8 9
5 9
1 9
10 11
1 11
11 12
12 13
13 14
1 14
9 14
13 15
9 15

Output can be like this:

10 12 6 3 14 11 4 13 15 8 9 7 5 2 1
afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
  • I understand the problem is to remove edges (wires) and nodes (cities); it is only feasible to remove a node if it is disconnected from all other nodes. Is that correct? – Codor Mar 23 '17 at 15:24
  • Yes i think that you said it correctly. I can provide full task but it is in Czech language. only rule is to NOT remove city what is like "bridge" between two other (only if there is more ways) –  Mar 23 '17 at 15:34
  • Would it be a feasible strategy to select an arbitrary node, remove all edges ajacent to it and finally remove the node? – Codor Mar 23 '17 at 15:36
  • my programming skills are not good enough to even create visualise graph in program. I only see it like points and wires on paper but i dont know how to make it "programish" –  Mar 23 '17 at 15:42
  • @Condor No, you don't delete edges at all. The constraint is that removing a vertex must not increase a number of connected components. – Abstraction Mar 24 '17 at 09:28
  • Problem is solved i can send source –  Mar 24 '17 at 14:36

1 Answers1

0

I think i solved it. It just need to do DFS Algorithm. After that result what I need is reversed DFS output.

For example if DFS output is 3,5,4,1,2 result is 2,1,4,5,3

This is DFS for C#: http://www.koderdojo.com/blog/depth-first-search-algorithm-in-csharp-and-net-core