Posts

Showing posts from March, 2017

Problem : Codeforces Round #406 (Div. 1) B [ Legacy ]( Dijakstra, Segment tree)

You are given graph N (10^5) nodes and starting node (S), You have to find min distance needed to go to all other nodes. Connections among nodes are a little bit different in the form of range type queries, which are: (1) you can open a portal from planet u to planet v with cost z. (2) you can open a portal from planet u to any planet with index in range [l, r] with cost z. (3) you can open a portal from any planet with index in range [l, r] to planet u with cost z. Idea: If we tried to make a adjacency matrix normally by traversing from l to r in (2) and (3) type of connection queries, it will surely time out. So, what we have to do is to think little bit about segmenttree representation of array. This representation allow us to make connection matrix only with LOGN adjacency nodes. So that we may proceed further. Lets build two types of segment-tree nodes , say UP segment tree , which will be used for (2) type of query and DOWN segmenttree which will be used for (3) type of