Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4247976
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:11:08+00:00 2026-05-21T04:11:08+00:00

let there be an undirected tree T , and let there be: T.leaves –

  • 0

let there be an undirected tree T, and let there be: T.leaves – all the leaves (each v such that d(v) = 1). we know: |T.leaves| and the distance between u and v for each u,v in T.leaves.

in other words: we have an undirected tree, and we know how many leaves it has, and the distance between every 2 leaves.

we need to find how many inside vertices (d(v)>1) are in the tree.

note: building the complete tree is impossible because if we have only 2 leaves but the distance between them is 2^30, it will take too long…

I tried to start from the shortest distance and count how many vertices are between them, and then adding the vertex closest to them, but for this I need some formula f(leaves_counted,next_leaf) but I could not manage to find that f…

any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:11:08+00:00Added an answer on May 21, 2026 at 4:11 am

    Continued from discussion in comments. This is how to check a particular (compressed) edge to see if you can attach the new vertex n somewhere in the middle of it, without iterating over the distances.

    tree

    Ok, so you need to find three numbers: l (the distance of the attach point from the left node of the edge in question), x (the distance of the new node from the attach point) and r (symmetrical to l.)

    Obviously, for every node y in set L (the left part of the tree), its distance to A must differ from its distance to n by the same number (lets call it dl which must be equal l + x). If this is not the case, there is no solution for this particular edge. Same goes for nodes in R, with dr and r + x respectively.

    If the above holds, then you have three equations:

    l + x = dl

    r + x = dr

    r+l = dist(A,B)

    Three equations, three numbers. If this has a solution then you have found the right edge.

    At worst you need to iterate the above for every edge, but I think it can be optimized – the distance check on L and R might exclude one of the parts of the tree from further search. It might also be possible to somehow get the number of nodes without even constructing the tree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say there is a report to compare charges with adjustments that outputs to
Let's say there are two python scripts that want to write data to the
Let's say that there is a solution that contains two projects (Project1 and Project2).
Let's assume there is a SQL Server 2008 table like below, that holds 10
Let's say there's an application that creates an account in AccountManager. User explores the
Let's say there's n amount of entries, each of whom can take the value
Let's say there are three consecutive function calls in one try block and all
Let's suppose there is an <img> element that has some onclick event handler. For
Let's say there is a mobile application that needs to make a sync request/query
Is there an algorithm or set of algorithms that would let you find the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.