QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100

#12034. 树 染 色

统计

给一棵 $n$ 个点的树,你需要给每个点选择一个 $\{1...m\}$ 中的颜色,使得树上相邻的两个点颜色不同。

显然这个问题过于简单了,于是我们还有 $k$ 个限制:第 $i$ 个限制形如 $(x_i,y_i)$ 表示第 $x_i$ 个点的颜色不能是 $y_i$。

求满足所有限制条件的合法染色方案数,由于答案可能过大,你只需要输出答案对 $998244353$ 取模后的值。

输入格式

第一行三个整数 $n,m,k$。

接下来 $n-1$ 行,每行两个正整数 $u,v$ 描述一条树边 $(u,v)$,保证给出的图是一棵树。

接下来 $k$ 行,第 $i$ 行两个正整数 $x_i,y_i$ 描述第 $i$ 条限制。

输出格式

输出一个非负整数,表示答案对 $998244353$ 取模后的值。

样例数据

样例 1 输入

4 3 3
1 2
2 3
2 4
1 1
2 2
3 3

样例 1 输出

8

子任务

Task1(13pts):满足 $n,m\leq 10^3$

Task2(9pts):满足 $k=0$

Task3(25pts):满足对于每条边 $(u,v)$ 都有 $|u-v|=1$

Task4(53pts):无特殊限制

对于所有数据,满足 $2\leq n\leq 2\times 10^5$,$2\leq m\leq 10^9$,$0\leq k\leq 4\times 10^5$,$1\leq u< v\leq n$,$1\leq x_i\leq n$,$1\leq y_i\leq m$

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.