A11517 | Strongly Connected Tournament
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is a chess tournament in All-Right-City. $n$ players were invited to take part in the competition. The tournament is held by the following rules:
1. Initially, each player plays one game with every other player. There are no ties;
2. After that, the organizers build a complete directed graph with players as vertices. For every pair of players there is exactly one directed edge between them: the winner of their game is the startpoint of this edge and the loser is the endpoint;
3. After that, the organizers build a condensation of this graph. The condensation of this graph is an acyclic complete graph, therefore it has the only Hamiltonian path which consists of strongly connected components of initial graph $A_{1}→A_{2}→...→A_{k}$ .
4. The players from the first component $A_{1}$ are placed on the first  places, the players from the component $A_{2}$ are placed on the next  places, and so on.
5. To determine exact place of each player in a strongly connected component, all the procedures from 1 to 5 are repeated recursively inside each component, i.e. for every $i=1,2,...,k$ players from the component $A_{i}$ play games with each other again, and so on;
6. If a component consists of a single player, then he has no more rivals, his place is already determined and the process stops.
The players are enumerated with integers from $1$ to $n$ . The enumeration was made using results of a previous tournament. It is known that player $i$ wins player $j$ ( $i<j$ ) with probability $p$ .
You need to help to organize the tournament. Find the expected value of total number of games played by all the players.
It can be shown that the answer can be represented as , where $P$ and $Q$ are coprime integers and . Print the value of $P·Q^{-1}$ modulo $998244353$ .
If you are not familiar with any of the terms above, you can read about them [here](https://en.wikipedia.org/wiki/Strongly_connected_component).
1. Initially, each player plays one game with every other player. There are no ties;
2. After that, the organizers build a complete directed graph with players as vertices. For every pair of players there is exactly one directed edge between them: the winner of their game is the startpoint of this edge and the loser is the endpoint;
3. After that, the organizers build a condensation of this graph. The condensation of this graph is an acyclic complete graph, therefore it has the only Hamiltonian path which consists of strongly connected components of initial graph $A_{1}→A_{2}→...→A_{k}$ .
4. The players from the first component $A_{1}$ are placed on the first  places, the players from the component $A_{2}$ are placed on the next  places, and so on.
5. To determine exact place of each player in a strongly connected component, all the procedures from 1 to 5 are repeated recursively inside each component, i.e. for every $i=1,2,...,k$ players from the component $A_{i}$ play games with each other again, and so on;
6. If a component consists of a single player, then he has no more rivals, his place is already determined and the process stops.
The players are enumerated with integers from $1$ to $n$ . The enumeration was made using results of a previous tournament. It is known that player $i$ wins player $j$ ( $i<j$ ) with probability $p$ .
You need to help to organize the tournament. Find the expected value of total number of games played by all the players.
It can be shown that the answer can be represented as , where $P$ and $Q$ are coprime integers and . Print the value of $P·Q^{-1}$ modulo $998244353$ .
If you are not familiar with any of the terms above, you can read about them [here](https://en.wikipedia.org/wiki/Strongly_connected_component).
输入格式
The first line of input contains a single integer $n$ ( $2<=n<=2000$ ) — the number of players.
The second line contains two integers $a$ and $b$ ( $1<=a<b<=100$ ) — the numerator and the denominator of fraction .
The second line contains two integers $a$ and $b$ ( $1<=a<b<=100$ ) — the numerator and the denominator of fraction .
输出格式
In the only line print the expected value of total number of games played by all the players. Print the answer using the format above.
输入输出样例
输入 #1
3 1 2
输出 #1
4
输入 #2
3 4 6
输出 #2
142606340
输入 #3
4 1 2
输出 #3
598946623
In the first example the expected value is $4$ .
In the second example the expected value is .
In the third example the expected value is .
In the second example the expected value is .
In the third example the expected value is .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted