Help with segment in a tree problem

Правка en6, от VietCT, 2020-02-19 20:30:15

Hi guys.

I have a problem want to ask you guys.

Problem: Given a tree with n nodes, m segments in a tree with 2 endpoints. Find the maximum number of segments satisfy that not exist two segments with the paths intersect. (n < 1e3, m < 1e5);

My solution (WA passed 4/5) is: Sort m segments by the depth of their LCA. If two segments have the same LCA, if one of them have the endpoint equal to their LCA i choose it ,else i choose the one have shorter length. After sorted, i pick it one by one.

My sub For example:

n = 6, m = 4;

edge:

1 2

2 3

3 4

3 5

3 6

segments:

1 3

4 5

5 6

6 4

So the answer is 2 because we can choose segment (1, 3) and segment (4, 5) as path 1 -> 3 = 1 -> 2 -> 3, path 4 — > 5 = 4 — > 3 -> 5.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en8 Английский VietCT 2020-02-19 20:34:45 10
en7 Английский VietCT 2020-02-19 20:32:49 56
en6 Английский VietCT 2020-02-19 20:30:15 79
en5 Английский VietCT 2020-02-19 20:29:27 98
en4 Английский VietCT 2020-02-19 20:28:24 275
en3 Английский VietCT 2020-02-19 17:21:27 16
en2 Английский VietCT 2020-02-19 17:21:02 2 Tiny change: 'Hi guys.``\nI have a' -> 'Hi guys.\nI have a'
en1 Английский VietCT 2020-02-19 17:20:46 576 Initial revision (published)