Cf D. Nauuo and Circle
https://codeforces.com/contest/1173/problem/D
题意:
给出你一个包含 n 个点的树,这 n 个点编号为 1~n;
给出一个圆,圆上放置 n 个位置,第 i 个位置对应树中的某个节点,并且不重复;
求在圆上还原这棵树后,使得边不相交的总方案数;
学习出:https://www.cnblogs.com/violet-acmer/p/10991346.html
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=;
const int M=2e5+;
struct node{
int nextt,v;
}e[M<<];
vector<int>son[M];
int head[M],n,tot;
ll fac[M],dp[M];
void addedge(int u,int v){
e[tot].v=v;
e[tot].nextt=head[u];
head[u]=tot++;
}
void dfs(int u,int f){
for(int i=head[u];~i;i=e[i].nextt){
int v=e[i].v;
if(v==f)
continue;
son[u].push_back(v);
dfs(v,u);
}
int flag=;
if(u!=)
flag=;
int k=son[u].size()+flag;
dp[u]=fac[k];
for(int i=;i<son[u].size();i++){
dp[u]=dp[u]*dp[son[u][i]]%mod;
}
}
ll solve(){
dfs(,);
return dp[]*n%mod;
}
int main(){
scanf("%d",&n);
fac[]=;
for(int i=;i<=n;i++)
fac[i]=(i*fac[i-])%mod;
memset(head,-,sizeof(head));
for(int i=;i<n;i++){
int u,v;
scanf("%d%d",&u,&v);
addedge(u,v);
addedge(v,u);
}
printf("%I64d",solve());
return ;
}
Cf D. Nauuo and Circle的更多相关文章
- Codeforces Round #564 (Div. 2) D. Nauuo and Circle(树形DP)
D. Nauuo and Circle •参考资料 [1]:https://www.cnblogs.com/wyxdrqc/p/10990378.html •题意 给出你一个包含 n 个点的树,这 n ...
- B. Nauuo and Circle 解析(思維、DP)
Codeforce 1172 B. Nauuo and Circle 解析(思維.DP) 今天我們來看看CF1172B 題目連結 題目 略,請直接看原題 前言 第一個該觀察的事情一直想不到,看了解答也 ...
- cf1173 D. Nauuo and Circle
链接 [cf]http://codeforces.com/contest/1175/problem/F) 思路 当1在1的位置做dp[i]为i的子树所有的方案. 一条性质是i的子树所占圆上的位置一定一 ...
- 【题解】Luogu CF1172B Nauuo and Circle
原题传送门 题意:在圆上有n个节点(珂以构成凸多边形),让你给节点编号,使得将题目给你的边(一棵树)没有交叉 我们钦定1为这个树的根节点.任意节点\(x\)的一颗子树的点应该是圆弧上连续的一段(我也不 ...
- CF 1172E Nauuo and ODT ——LCT
题目:http://codeforces.com/contest/1172/problem/E LCT好题. 考虑对每个颜色求出 “不是该颜色的点组成的连通块的 siz2 之和” .每个颜色用 LCT ...
- Codeforces Round #564 比赛总结
这次是中国大佬出题,结果被虐惨了. A. Nauuo and Votes #include<bits/stdc++.h> #define Rint register int using n ...
- Codeforces Round #564 (Div. 1)
Codeforces Round #564 (Div. 1) A Nauuo and Cards 首先如果牌库中最后的牌是\(1,2,\cdots, k\),那么就模拟一下能不能每次打出第\(k+i\ ...
- CF #579 (Div. 3) A.Circle of Students
A. Circle of Students time limit per test2 seconds memory limit per test256 megabytes inputstandard ...
- CF - 652F Ants on a Circle
题目传送门 题解: 先观察蚂蚁相撞, 可以发现, 如果我们将相撞的2个蚂蚁互换位置的话,蚂蚁相当于没有碰撞体积,直接穿过去了.所以我们可以直接计算出最终哪些位置上会有蚂蚁. 接下来就需要知道蚂蚁们的最 ...
随机推荐
- python clickZan
import pyautogui,time,random pyautogui.PAUSE = 3 pyautogui.FAILSAFE = True width, height = pyautogui ...
- CountUp.js 数字跳转效果小插件
CountUp.js 实现数字跳转效果的小插件 //调用方法 const easingFn = function (t, b, c, d) { var ts = (t /= d) * t; var ...
- 递归(VBA实现)
案列: 给定n个数,取任意g个数之和等于h的组合. 采用递归的方式实现: Option Explicit Dim arr1(1 To 10000, 1 To 1) As String Dim k, g ...
- Python调用OpenCV读显写
OpenCV提供了python的接口,而且很重要的一点是python下的很多接口名与C++的接口名是一样的,这一篇先记录python调用OpenCV去读取图像.显示图像和保存图像. 1.OpenCV读 ...
- Ubuntu Kylin 14.04LTS 开机后卡在登陆界面,可以进入字符界面,或者登陆后鼠标不显示但是管用
2014年4月27日,距离中期检查还有七天,基本上什么也没做,特别着急,雨已经下了快一天了,中午用美团外卖定的黄焖排骨,MD,什么玩意,那么一点点就18块钱,一看就不值五块钱,发誓再也不吃,最重要的是 ...
- Python Learning Day5
Response响应 import requests response = requests.get('https://baidu.com') # response响应 print(response. ...
- .NET CORE 获取微信支付回调
1.获取微信支付的回调的数据 Stream stream = HttpContext.Request.Body; byte[] buffer = new byte[HttpContext.Reques ...
- Api_hook 拦截 messageBox 等函数
library hookdll; uses SysUtils, Windows, Classes, unitHook in 'unitHook.pas'; {$R *.res} const HOOK_ ...
- Delphi流的操作_文件合并
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- Swagger注解及参数细节的正确书写。
今天新开了一个api文件,结果怎么搞也在swagger里显示不出来,浪费半天后,去问老员工了. 一般有俩原因, 1.idea缓存,重启idea即可. 2.注解和参数上的修饰有问题,或者请求method ...