yosupo06 / library-checker-problems

The problem data (Test case generator, judge's solution, task, ...) of Library Checker
https://judge.yosupo.jp/
Apache License 2.0
488 stars 114 forks source link

[Problem proposal] Unionfind with Potential #1194

Open Misuki743 opened 3 days ago

Misuki743 commented 3 days ago

Problem name: Unionfind with Potential

Problem

Given a graph with $N$ vertices and $0$ edges, each vertex have some weight $w_v$ on it. Process the following $Q$ queries in order:

Solution

Maintain difference of $wv$ and $w{p_v}$ in Unionfind.

Constraint

Note / Disucussion

maspypy commented 2 days ago

Thank you! Since this data structure can handle groups (not limited to commutative groups), I want to deal with non-commutative groups. Here are some examples of the types of problems we can consider:

Each vertex has values $(x[0], \ldots, x[N-1])$. These values are unknown.

[Query 1] Given $(u, v, a, b)$, where $a \neq 0$. This means the information $x[v] = a x[u] + b \pmod{998244353}$. This information is valid if it does not contradict any previously valid information. Output whether this information is valid or invalid.

[Query 2] Given (u, v, x). Based on the previously valid information and assuming x[u] = x, determine x[v] or print -1 if it can't be determined.

Misuki743 commented 2 days ago

Seems nice, but to compute the inverse of affine would require computation of modulo inverse, which would make the time complexity increase from $O(q \alpha(n))$ to $O(q (\alpha(n) + \lg \text{mod}))$, maybe it's better to find a way to avoid extra cost not from the data structure itself? For example, change to another non-commutative group whose inverse won't be that costly, or just gives affine and its inverse in the input?