Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

Блог пользователя hexor

Автор hexor, 12 лет назад, По-английски

I want the ask aquestion. "You have a DAG(directed acyclic graph) which is the contain n(1<=n<=300.000) nod. How many nodes can you go if you will start nod i(1<=i<=n). You must find answer for all nod."

  • Проголосовать: нравится
  • +34
  • Проголосовать: не нравится

»
12 лет назад, скрыть # |
 
Проголосовать: нравится -18 Проголосовать: не нравится

Problem statement is not clear. Do you have a link to the original problem?

»
12 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +9 Проголосовать: не нравится

we can use dfs like idea i think. For every node there will be a mask which will indicate which nodes are reachable from this node. To calculate the mask of a node 'U' we can recursively calculate the info (mask) for the child nodes of 'U'. And to find the mask of U we can use bitwise OR operation.

The problem is as total node is 300000 we have to use an array of integers to define the mask. if we use int then the mask array will be of size 300000/32 = 9375. if we use long long then the mask array will be of size 300000/64 = 4688. is this a Online judge problem? may be the limit is not that big. can you provide the link if it is an online judge problem.

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Your question is exactly the same with http://www.spoj.com/problems/DAGCNT2/.

»
12 лет назад, скрыть # |
← Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

I think you can use a DP approach for this problem. I should be O( |V| + |E| ).

For each node that hasn't been calculate you run a dfs( u ). Where dfs(u) will return how many nodes you can reach from there and for each of its children you will run a dfs( ) that will save the number of nodes that each of its children can reach.

Well, this is my idea. Sorry if i have some grammar or spelling mistakes. I am trying to fix it.

  • »
    »
    12 лет назад, скрыть # ^ |
    ← Rev. 5  
    Проголосовать: нравится 0 Проголосовать: не нравится

    This algorithm will not run correctly. for example we have four nodes. first node have two children which are second and third node. Second and third node have a child which is fourth node. fourth node haven't got a child. we called dfs( 1 ).

    dfs(1) = dfs(2)+dfs(3)+1.

    dfs(2) = dfs(4)+1 = 2.

    dfs(3) = dfs(4)+1 = 2.

    dfs(1) = 5.

    for first node we count the fourth node twice. normally dfs(1)=4 but we find dfs(1)=5

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Someone told me a randomized algorithm can run really fast, and for at least 90% of n, its answers' relative error is at most 10%. However, I could not remember the algorithm......

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Process vertices in inverse topological order.

For each vertex the result is 1 + sum of results for children

O(N + M) or I missed something?