minhi1's blog

By minhi1, history, 4 months ago, In English

Given a tree with n nodes and n — 1 edges. There are total k different colors (k <= n). Each node i has a color c(i) (1 <= c(i) <= k). Cost of a subtree u equals number of distinct colors in subtree u.

Given q queries. Each query belongs to two types: Type 1: (1, u, nw) is to change the color of node u to nw. (1 <= nw <= k) Type 2: (2, u) print the Cost of subtree u.

Constraints: 1 <= n <= 5e5 1 <= q <= 3e5

So far I have only thought of counting distinct colors without updating queries by small-to-large or BIT. For updating, I just know that type 1 query will affect all the ancestors of u. Still, I don't know the optimized way yet. Can you guys help me ? Thanks.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By minhi1, history, 6 months ago, In English

Given a connected graph with n nodes and m edges (n, m <= 1e5). There are q queries (q <= 1e5), each has type of (u, d, c) means to color all nodes which have the smallest distance to u <= d color c (d <= 10, c <= 1e5). What is the color of n nodes after q queries.

I can only do smaller subtask when n,m,q <= 2000 with bfs. I do think about solving queries backward and color nodes that are empty but still don't know how to optimize it. Can anyone help me. Thanks.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it