I. Kawaii Courier

Codeforces
IDCF10283I
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Once there was a courier named Kujou Kawaii, whose work was to collect packages from people around the city. The city consisted of $n$ communities, numbered from $1$ to $n$, together with $n -1$ bidirectional roads connecting them. The express distribution center of this city was located at the community numbered $k$. Of course, any two communities were guaranteed to be connected by these roads. Kujou's electromobile was so small that she could only carry packages from $1$ community at the same time. She would always first deliver packages from the community numbered $1$, then those from the one numbered $2$, etc., and finally the packages from the one numbered $n$. Let's calculate Kujou's tiredness index after a whole day of work! We only consider the trip from each community to the express distribution center. Unfortunately, Kujou had no sense of direction. On arriving at a community, she would uniformly randomly choose a road (including the one she came from) to follow, until she finally reached the community where the express distribution center was located. Suppose the trip from the community numbered $i$ to the express center passed $d_i$ roads. Kujou's tiredness was influenced by three factors. It can be shown that $m_i$ can be expressed as an irreducible fraction $frac(p_i, q_i)$, where $p_i$ and $q_i$ are integers. It is then guaranteed in all test cases that $q_i not equiv 0 pmod 10^9 + 7$. In this case, $m_i$ modulo $10^9 + 7$ is well-defined, which is some integer $m '_i$ such that $m '_i q_i equiv p_i pmod 10^9 + 7$. Furthermore, you only need to output $m '_1 plus.circle \\dots plus.circle m '_n$ to prevent large output, where $plus.circle$ denotes the bitwise XOR operation. The first line contains four integers $n$, $k$, $p_x$ and $q_x$ ($2 <= n <= 10^5, 1 <= k <= n, 1 <= p_x <= q_x <= 10^7$), where $x$ is given in the form $p_x \/ q_x$. Each of the next $n -1$ lines contains two integers $u$ and $v$ ($1 <= u, v <= n$), indicating that there was a road connecting the community numbered $u$ and the one numbered $v$. It is guaranteed that all communities are connected by these $n -1$ roads. Print $m '_1 plus.circle \\dots plus.circle m '_n$. In the second example, $m_1 = 0$, $m_2 = frac(36, 49)$, $m_3 = frac(48, 49)$. ## Input The first line contains four integers $n$, $k$, $p_x$ and $q_x$ ($2 <= n <= 10^5, 1 <= k <= n, 1 <= p_x <= q_x <= 10^7$), where $x$ is given in the form $p_x \/ q_x$.Each of the next $n -1$ lines contains two integers $u$ and $v$ ($1 <= u, v <= n$), indicating that there was a road connecting the community numbered $u$ and the one numbered $v$. It is guaranteed that all communities are connected by these $n -1$ roads. ## Output Print $m '_1 plus.circle \\dots plus.circle m '_n$. [samples] ## Note In the second example, $m_1 = 0$, $m_2 = frac(36, 49)$, $m_3 = frac(48, 49)$.
**Definitions** Let $ n \in \mathbb{Z} $ be the number of communities, $ k \in \{1, \dots, n\} $ the location of the express center. Let $ G = (V, E) $ be a tree with $ V = \{1, \dots, n\} $, $ |E| = n-1 $, and edge set $ E $. Let $ d_i $ be the graph distance (number of edges) from node $ i $ to node $ k $. Let $ x = \frac{p_x}{q_x} \in (0,1) $ be a given rational probability. For each community $ i \in \{1, \dots, n\} $, define $ m_i $ as the expected number of steps for a random walk starting at $ i $, where at each node the walker chooses uniformly at random among all incident edges (including the one just traversed), until reaching $ k $. Let $ m_i = \frac{p_i}{q_i} $ in lowest terms. Define $ m'_i \in \mathbb{Z}/(10^9+7)\mathbb{Z} $ such that $ m'_i \cdot q_i \equiv p_i \pmod{10^9+7} $. **Constraints** 1. $ 2 \leq n \leq 10^5 $ 2. $ 1 \leq k \leq n $ 3. $ 1 \leq p_x < q_x \leq 10^7 $ 4. The graph is a tree. 5. $ q_i \not\equiv 0 \pmod{10^9+7} $ for all $ i $. **Objective** Compute $ \bigoplus_{i=1}^n m'_i $, where $ \oplus $ denotes bitwise XOR.
API Response (JSON)
{
  "problem": {
    "name": "I. Kawaii Courier",
    "description": {
      "content": "Once there was a courier named Kujou Kawaii, whose work was to collect packages from people around the city. The city consisted of $n$ communities, numbered from $1$ to $n$, together with $n -1$ bidir",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10283I"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Once there was a courier named Kujou Kawaii, whose work was to collect packages from people around the city. The city consisted of $n$ communities, numbered from $1$ to $n$, together with $n -1$ bidir...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of communities, $ k \\in \\{1, \\dots, n\\} $ the location of the express center.  \nLet $ G = (V, E) $ be a tree with $ V = \\{1, \\dots, n\\} $, $ |E...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments