yse's blog

By yse, 4 weeks ago, In English

Thanks for participating in the contest. I hope you enjoyed the problems :)

Rating Predictions
Rate the contest!
Rate the difficulty!

A — Koshary

Hint
Solution
Code (C++)
Rate the problem!

B — Party Monster

Hint
Solution
Code (C++)
Rate the problem!

C — Snowfall

Hint 1
Hint 2
Solution
Code (C++)
Rate the problem!

D — Palindromex

Hint 1
Hint 2
Solution
Code (C++)
Bonus
Rate the problem!

E — It All Went Sideways

Hint 1
Hint 2
Solution
Code (C++)
Rate the problem!

F — It Just Keeps Going Sideways

Thanks to chromate00 for suggesting a modification to problem E, which resulted in this problem.

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the problem!

G — Drowning

Hint 1
Hint 2
Hint 3
Solution
Code (C++, using ordered set)
Code (C++, using Fenwick Tree and coordinate compression)
Rate the problem!

H — Fallen Leaves

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the problem!
  • Vote: I like it
  • +84
  • Vote: I do not like it

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how 11 days ago?

»
3 weeks ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

The example note in C made me question reality for a moment...

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Fast editorial

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Mann ..Stack saved me at the last minute in E

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Anyone managed to solve H with some greedy simulation ?

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    I dont know can it be called greedy. I just did simple dp, like we are not deleting leaves, and rerooted it.

    • »
      »
      »
      3 weeks ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I mostly meant simulating the process moving the leaves up by one and when they meet adding the pair, the problem is that sometimes its not optimal to remove a pair since one of the leaves might be the one we should eventually leave off.

      • »
        »
        »
        »
        2 weeks ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        oh yeah! This is literally what I did. Addiotoinally if we leave the longest leaf without pair in our dp, it will work. We could delete not the optimal one, to avoid it, we just check for every root (reroot) (sorry for late answering)

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Thanks for the contest , I just participated out of speed-running first few problems.

Spoiler

btw C is a nice problem.

I looked other problems , They look interesting too.

Congrats on this successful contest .

»
3 weeks ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

wtf we have nearly identical solution even the naming convention for C this is my submission holy shit i hope i don't get banned lol.

373106639

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    my sol almost exactly same bruh

    • »
      »
      »
      3 weeks ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it
      #include <bits/stdc++.h>
      using namespace std;
      
      #define endl '\n'
      #define all(x) (x).begin(), (x).end()
      
      using ll = int64_t;
      
      void test_case() {
          int n; cin >> n;
          vector<ll> a, b, c, d;
          vector<ll> ans(n);
          for (int i = 0; i < n; i++) {
              ll x; cin >> x;
              if (x % 6 == 0)
                  a.push_back(x);
              else if (x % 2 == 0)
                  b.push_back(x);
              else if (x % 3 == 0)
                  c.push_back(x);
              else
                  d.push_back(x);
          }    
          for (ll x : a)
              cout << x << ' ';
          for (ll x : b)
              cout << x << ' ';
          for (ll x : d)
              cout << x << ' ';
          for (ll x : c)
              cout << x << ' ';
          cout << endl; 
      }
      
      int main() {
          ios::sync_with_stdio(false);
          cin.tie(nullptr);
          int T; cin >> T;
          for (int i = 0; i < T; i++)
              test_case();
      }
      
    • »
      »
      »
      3 weeks ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it

      i hope we don't get reported then bruv!!

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    ah hell nah

    My submission

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    dont be worry, as you can see its not a particularly difficult problem, so its just normal for ideas or coding styles to overlap (at least there many people do in that way).

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks for the insanely fast editorial, and for the good problems you have put up in the contest!

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

I'm genuinely impressed with problem G, how can one come up with that idea?

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

glad to know that there's solution without using Fenwick Tree/Segment Tree in problem F.

»
3 weeks ago, hide # |
Rev. 2  
Vote: I like it +2 Vote: I do not like it

who used complex Manacher algorithm for D or just dumb me :D

»
3 weeks ago, hide # |
Rev. 5  
Vote: I like it +11 Vote: I do not like it

Answer to the $$${Bonus}$$$ $$${Problem}$$$ $$${D:}$$$

My approach uses greedily finding the longest palindromic subsegments, but the concept of this approach works for the idea discussed in the Editorial as well.

Since there are $$${exactly}$$$ $$${2}$$$ occurrences of each element in the array, therefore the number of pairs which are equal and of the form $$$a_{i}=a_{j}$$$ is only $$${n}$$$.

Also, since the $$${positions}$$$ of each element is $$${fixed}$$$, therefore, for each $$${center}$$$, if you find palindrome with that center, there are $$${unique}$$$ set of palindromic pairs.

If we iterate on the array, and at the current index we try to find the palindromic pair of this element. If the palindromic pair is at an index $$${j \geq i+1}$$$, then we check for each pair $$${(i, j)}$$$ $$${,}$$$ $$${(i+1, j-1)}$$$ $$${,}$$$ $$${(i+2, j-2)}$$$ $$${,}$$$ $$${....}$$$ $$${,}$$$ $$${(i+k, j-m)}$$$, where $$${i+k \leq j-m}$$$. While checking we will also mark them as visited in a visited array.

If at any point we get to know that this selected subsegment is not palindromic we simply just increment $$${i}$$$ to the index where the palindromic condition first failed, i.e., $$${i=x}$$$, where $$${a[x] \neq a[y]}$$$ for some indices $$${x}$$$ and $$${y}$$$ during the checking of palindromic condition. After incrementing, check for other possible palindromic subsegments by repeating the process.

But, if we find that the selected subsegment was a palindrome, then we iterate on the visited array from $$${0}$$$ to $$${n}$$$, and store the maximum $$${mex}$$$ found yet. Then we increment the $$${i}$$$ to $$${j+1}$$$, where $$${j}$$$ was the index of the palindromic pair of the element at index $$${i}$$$.

We increment $$${i}$$$ to $$${j+1}$$$ because we have found the longest palindromic subsegments greedily, and since there are $$${exactly}$$$ $$${2}$$$ occurrences for each element in the array, therefore $$${any}$$$ subsegment of the palindromic subsegment $$${(i, j)}$$$ cannot be present in any other palindromic subsegment.

Hence, we only are iterating on the array just $$${once}$$$ and we visit each and every element just $$${once}$$$. Therefore, only $$${O(n)}$$$ operations are performed in greedily finding the longest palindromic subsegment.

Now, talking about the finding of $$${mex}$$$. Since $$${0}$$$ can be present in $$${at}$$$ $$${most}$$$ $$${2}$$$ palindromic subsegments, therefore, for all other palindromic subsegments the $$${mex}$$$ can be found in just $$${one}$$$ operation $$${( mex}$$$ would be zero in that case $$${)}$$$.

$$${At}$$$ $$${most}$$$ $$${2}$$$ subsegments will take $$${O(n)}$$$ time to find their $$${mex}$$$, therefore in total it takes $$${O(2*n-2+2*n)}$$$ $$${=}$$$ $$${O(n)}$$$.

Therefore, the total number of operations turn out to be $$${O(n) + O(n)}$$$ $$${=}$$$ $$${O(n)}$$$.

My submission uses the same idea.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can fentree be used in E like in F

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Problem F was a modification/extension of problem E. This is the first time I have seen this sort of "multi part" problem in a codeforces round despite it being quite common in national/international Olympiads. Personally, I find these sorts of problems quite enjoyable. Kudos to the problem authors.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for the bonus of problem D

I exactly solved the problem like that but for the proof my intuition told me this is correct <3

»
3 weeks ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

..

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    It was a big mistake to tell people to check your solution; they hacked you And tbh, I wanted to hack you but wasn't fast enough

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for the bonus of problem D

This fits the time limit because i got Accepted for same idea

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Instant tutorial, the contest was great, and the author is Egyptian!!!

I can't ask for a better thing, thank you, yse

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why is it not necessary to have at least one of $$$a_l$$$ or $$$a_r$$$ to be positive in a good subarray? (Problem G)

»
3 weeks ago, hide # |
Rev. 2  
Vote: I like it +9 Vote: I do not like it

instead of making suffix min array in problem E, we can simply track the max gain by maintaining two state variables...

My Code
»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

hmm... what if we want to maximize the number of subarrays that are divisible by 6 in problem C? And what if the number by which the product of the array numbers should be divided is arbitrary? It sounds interesting. Thanks for the contest.

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    interesting

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    To maximize the number of subarrays containing at least one occurrence of $$$x$$$, you can formulate the problem as follows:

    Let the number of occurrences of $$$x$$$ be $$$k$$$. These $$$k$$$ elements divide the array into $$$k+1$$$ segments of lengths $$$x_1, x_2, \dots, x_{k+1}$$$. The number of subarrays that include at least one $$$x$$$ is:

    $$$\sum_{1 \le i \lt j \le k+1} x_i x_j$$$

    This is a known optimization problem where we use the identity:

    $$$\left( \sum_{i=1}^{k+1} x_i \right)^2 = \sum_{i=1}^{k+1} x_i^2 + 2 \sum_{1 \le i \lt j \le k+1} x_i x_j$$$

    Since the total sum of elements $\sum_{i=1}^{k+1} x_i = n-k$ is constant, maximizing the sum of pairwise products $$$\sum_{1 \le i \lt j \le k+1} x_i x_j$$$ is equivalent to minimizing the sum of squares $$$\sum_{i=1}^{k+1} x_i^2$$$ which is minimized when the elements are distributed as evenly as possible ($$$x1 \approx x2 \approx x3 \approx \dots \approx x_{k+1}$$$).

    As for the divisors of $$$x$$$, i believe grouping them together in contiguous blocks to act as new singular elements is optimal though i couldn't prove it.

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

I realised the solution for E in the last 10 minutes but ran out of time :( Solved it 15 minutes later though :P

This was a fun first contest

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

contest was fun . feels like a div 3 contest. C was interesting for me. couldnt solve d and e but i saw e problem earlier contest. overall the contest was fun. i hope everyone was satisfied with contest

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
Proof of Bonus D
»
3 weeks ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

In F I used difference array to track the sum of all position which contains height x, and after it I check how many blocks finally will be in right side, we can easily find their positional sum. and the answer without removing any block will be sum of all height's answer which is their final positional sum — initial sum.

void solve() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	for (auto &it : a)cin >> it;

	vector<ll>b(n + 2);
	ordered_set st;
	for (int i = 0; i < n; i++) {
		b[1] += i + 1;
		st.insert(a[i]);
		b[a[i] + 1] -= i + 1;
	}

	for (int i = 1; i <= n + 1; i++) {
		b[i] += b[i - 1];
	}
	vector<ll>c(n, 1e8);
	ll mn = 1e8;
	for (int i = n - 1; i >= 0; i--) {
		mn = min(mn, a[i]);
		c[i] = mn;
	}

	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		ll t = st.order_of_key(i - 1);

		ll tot = n * (n + 1) / 2;

		ll r = n - t;

		ll prev_sum = r * (r + 1) / 2;

		sum += tot - prev_sum - b[i];

	}

	ll mx = sum;

	for (int i = n - 1; i >= 0; i--) {
		ll t = st.order_of_key(a[i] - 1);

		mx = max(mx, sum + t - (n - i));

	}

	cout << mx << endl;

}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for the problem G isn't it just counting inversion with few more conditions, so can't it just be done using merge sort yse ?

»
3 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

I have Done D using Brute

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Suffix minimum idea in E is actually neat !

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I can't code, can't find a job, can't have GF, what I can do god, Please save me.

Started CP at the age of 24 being a unemployed, who is aiming to become CMaster at CF.

Fingers crossed :X)

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My apparch for F (Segment Trees)

Used a lazy segment tree to track, for each element, how much distance it can move based on how many columns to the right support its height.

While iterating right → left, updated this tree to maintain:

for each height h → count of future columns with ≥ h

and used it to compute total movement (ans).

Used a second segment tree to maintain frequency of heights (prefix counts).

This second tree is used to simulate removing one element, by counting:

how many elements (heights ≥ a[i]) gain +1 movement

(inversion-like counting).

Final answer:

base movement + best gain from removing one index

code in java:- https://mirror.codeforces.com/contest/2227/submission/373194545

»
3 weeks ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

D can be solved using binary search. We can find if ans is atleast x+1.in O(n)

If ans is atleast x+1 , means all ele 0 to x are present , thus get both the positions of x. Now 2 possiblities , Both x are present in our palindrome or Only one.

For both x case , we have both position of x , hence find its centre and expand palindrome as much as possible and check if all elements from 0 to x are present. For single x , do same , now centre is positon of x itself. (Check for Both positions of x)

Link -(https://mirror.codeforces.com/contest/2227/submission/373144878)

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

H is great, the edge-perspective idea is interesting.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think my solution is the same as Bonus Problem D: 373133653, instead of brute-forcing all over the center, i did brute-force from the boundary.

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Since each element appears exactly twice. Each value can only be in at most 3 different situations (they can be the matching pairs, or they can be the center). If they are the matching pairs, they can only be visited exactly one times. If they are the center, they can be visited by other element at most 2 times. This gives us O(N) solution.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone explain the solution to the Bonus question of D ?

»
3 weeks ago, hide # |
Rev. 3  
Vote: I like it +2 Vote: I do not like it

By the way, G is solvable without having to use PBDS / segtree structures, which is helpful for easier implementation

If we twist the perspective a little bit from the provided solution, then pref[l-1] < pref[r] when l is odd, and pref[r] < pref[l-1] when l is even. Notice how in both cases, the smaller side (l-1 and r respectively) are even, and the larger sides are odd. And in each case, r appears later than l-1 and vice versa. Since l-1 and r are different parity, they cannot be equal and hence each case goes either in the 'smaller' or 'larger' category, which these two criteria fit exactly. This means that we can just search for the number of EVERY pref[#odd] (regardless if the index is larger or smaller than that of the even index) that are larger than each pref[#even]. Since this requires no element addition or subtraction, this can be done with sorting + binary search.

Implementation

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

E and F are amazing!

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

this was my first contest, letsgo

solved a and b, and almost solved c, didn't know how to sort numbers that aren't divisible directly by 6, gotta work on my math

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

what am i doing i tried to maximise the subarrays in C

»
3 weeks ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

the persons who use ai , their family all died already btw, an excellent contest

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

a similar problem after c?

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

an elegant solution for F :) 373205287

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

in problem D, why couldn't we check if there is a palindrom bitween the tow zeros ,then if there is we check the number on the tow sides of it to make it longer, otherwise we assume that every zero is the center of the palindrom and the answer will be the maximum mex of each of the palindrims? I hope you understand my quastion '_' ^_^ 2227D - Palindromex

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i got braingasm after solving A and B

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Wow, this was my first contest. Solved problems A, B and C smoothly, struggled in D.

But a great experience overall!!!

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can it be said for D given the constraints that two palindromic subarrays cannot intersect unless one is completely inside the other, and then we can do a brute force on all palindromic subarrays which cant be extended by adding one element on each side? the only exception i can think of is a subarray of the form abab which can still be handled within the code

»
3 weeks ago, hide # |
 
Vote: I like it +9 Vote: I do not like it
»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

yse Why has my rating not updated for this round? Why does it show a delta of 0?

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The problems are interesting.

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

guys i made it :DD

»
3 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I think there's a typo in the "Hint 2" of problem E, it should be "The number of rows/cubes that stay in column i is exactly the suffix minimum s_i."

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

good contest

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I used a Fenwick Tree for all of problems E, F and G.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

SegmentTreeforces

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

in G what sort of intuition would lead one to guess that alternatingsum>0 is a sufficient condition?

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

I did problem F completly differently

If you look at $$$a[i]$$$ and some block at height $$$y \leq a[i]$$$, the number of times that that block contributes to the total motion is the number if $$$j \gt i$$$ such that $$$a[j] \lt y$$$. If we loop through the array backwards and mantain a histogram $$$h[x]$$$ of the number of times $$$a[j] = x$$$ for $$$j \gt i$$$, then the number of times a block at height $$$y$$$ contributes to the motion is

$$$h[y-1] + h[y-2] + h[y-3] + \dots$$$

$ Adding this up for all $$$y \leq a[i]$$$ ands, the contribution is

$$$h[a[i]-1] + 2h[a[i]-2] + 3h[a[i]-3] + \dots = \sum_{k=0}^{a[i]} (a[i] - k) h[k] = a[i]\sum_{k=0}^{a[i]} h[k] - \sum_{k=0}^{a[i]}kh[k]$$$

$ Finally we can mantain two fenwick trees representing sums of $$$h[k]$$$ and $$$kh[k]$$$ to get the answer. You can get the maximum increase from decrementing one $$$a[i]$$$ with the same method

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

KAN MikeMirzayanov

Cant we do anything about blatant cheaters?

We can easily spot cheaters in this contest.

For example, cookingDSA is clearly using AI solutions in this contest.

Are there going to be any updates in the near future regarding anti-cheat tools, etc.?

If not, we can float a blog where people can share their ideas so that cheaters will be reduced.

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

First time upsolved all the problems of a Div-3 round!! Problem H was most interesting and only painful problem for me.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve H if the set S contains all vertices of the tree?

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    the only way for a tree to be only leaves is if $$$n=1$$$ or $$$n=2$$$ but the problem gives $$$3 \leq n$$$ so you don't have to think about that

    • »
      »
      »
      3 weeks ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      i meant the case where S is defined to include all vertices of the tree, not just the leaves, this leads to a different problem

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem H, there is also a sneaky dp solution which somehow passes without TLE

I basically try to root the tree at each non leaf node and then try to calculate the best possible cost for that root.

373383493

This solution TLEs if you try to root the tree also on leaf nodes

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Hacked, I used a tree that looks like this:

    Tree

    Vertex $$$1$$$ would be forced to sort its neighbors $$$O(n)$$$ times, making the complexity $$$O(n^2 \log n)$$$.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

H is so confused

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

the solution for H is so confused you said If cnt[u], is even, all leaves inside this subtree can be paired with each other internally. This edge does not need to be crossed by any path. so what about the sons of vertex u get used already, then u become the new leaf ? and cnt[u] = (adj[u].size() == 1); is so confused , what ru cal for ??? obviously not cal for the num of leaves

you said: let cnt[u] be the total number of leaves in the subtree rooted at u but yoru cnt[1] equal to 3 on sample 1, obviously the num of leaves is 2 who can explain this for me plz!!!

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    root in 1 . if 1 sons of vertex u get used , another sons of this vertex u have been paired with this . every node (expect root) have 1 father , so if adj = 1 , we expect father node cause adj = 0 , this is leaf

    • »
      »
      »
      3 weeks ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      thank you! now i have solved the problem, i misunderstood the definition of the leaf node, , ans the cnt of nodes is only, no matter with the root, thanks a lot btw, i dont read this sentence of the problem : this set is determined from the original tree and does not change, my bad XD

»
3 weeks ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

I love problem G

»
2 weeks ago, hide # |
Rev. 5  
Vote: I like it 0 Vote: I do not like it

C