QOJ.ac

QOJ

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

#7498. 网络图

Statistics

现在给定一颗 $n$ 个点的树 $T$,再给定 $m$ 个点对。

现在请你给这 $m$ 个点对各确定一个方向,得到 $m$ 条树上的有向路径,满足:

  • 对于树上的每条边 $(u, v)$,设 $l$ 为这 $m$ 条有向路径中会从 $u$ 到 $v$ 的数量,$r$ 为会从 $v$ 到 $u$ 的数量。需要保证 $|l - r| \leq 1$。

可以证明一定有解。

输入格式

第一行输入两个正整数 $n, m$,表示树的点数和给的点对数量。

接下来 $n-1$ 行每行输入两个正整数 $u, v$,表示一条树上的边。

接下来 $m$ 行每行输入两个正整数 $a, b$(保证 $a\neq b$),表示一个点对。

输出格式

输出 $m$ 行,第 $i$ 行要么输出对应输入的第 $i$ 对点对 $a, b$,要么输出 $b, a$,表示路径的方向。

样例数据

样例 1 输入

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

样例 1 输出

3 2
2 4

子任务

对于 $20\%$ 的数据,保证 $m\leq 8$。

对于 $40\%$ 的数据,保证 $m\leq 16$。

对于另外 $20\%$ 的数据,保证树是一条链($i$ 和 $i+1$ 有边)。

对于另外 $20\%$ 的数据,保证树是一颗菊花($1$ 和 $i$ 有边)。

对于 $100\%$ 的数据,保证 $1\leq n, m\leq 10^5$。

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.