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的更多相关文章

  1. 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 ...

  2. B. Nauuo and Circle 解析(思維、DP)

    Codeforce 1172 B. Nauuo and Circle 解析(思維.DP) 今天我們來看看CF1172B 題目連結 題目 略,請直接看原題 前言 第一個該觀察的事情一直想不到,看了解答也 ...

  3. cf1173 D. Nauuo and Circle

    链接 [cf]http://codeforces.com/contest/1175/problem/F) 思路 当1在1的位置做dp[i]为i的子树所有的方案. 一条性质是i的子树所占圆上的位置一定一 ...

  4. 【题解】Luogu CF1172B Nauuo and Circle

    原题传送门 题意:在圆上有n个节点(珂以构成凸多边形),让你给节点编号,使得将题目给你的边(一棵树)没有交叉 我们钦定1为这个树的根节点.任意节点\(x\)的一颗子树的点应该是圆弧上连续的一段(我也不 ...

  5. CF 1172E Nauuo and ODT ——LCT

    题目:http://codeforces.com/contest/1172/problem/E LCT好题. 考虑对每个颜色求出 “不是该颜色的点组成的连通块的 siz2 之和” .每个颜色用 LCT ...

  6. Codeforces Round #564 比赛总结

    这次是中国大佬出题,结果被虐惨了. A. Nauuo and Votes #include<bits/stdc++.h> #define Rint register int using n ...

  7. Codeforces Round #564 (Div. 1)

    Codeforces Round #564 (Div. 1) A Nauuo and Cards 首先如果牌库中最后的牌是\(1,2,\cdots, k\),那么就模拟一下能不能每次打出第\(k+i\ ...

  8. CF #579 (Div. 3) A.Circle of Students

    A. Circle of Students time limit per test2 seconds memory limit per test256 megabytes inputstandard ...

  9. CF - 652F Ants on a Circle

    题目传送门 题解: 先观察蚂蚁相撞, 可以发现, 如果我们将相撞的2个蚂蚁互换位置的话,蚂蚁相当于没有碰撞体积,直接穿过去了.所以我们可以直接计算出最终哪些位置上会有蚂蚁. 接下来就需要知道蚂蚁们的最 ...

随机推荐

  1. POJ 1887:Testing the CATCHER 求递减序列的最大值

    Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16131   Accepted: 5 ...

  2. POJ 1159:Palindrome 最长公共子序列

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 56273   Accepted: 19455 Desc ...

  3. golang实现单链表

    package main import "fmt" type Object interface{} type Node struct { data Object next *Nod ...

  4. Python笔记_第五篇_Python数据分析基础教程_NumPy基础

    1. NumPy的基础使用涵盖如下内容: 数据类型 数组类型 类型转换 创建数组 数组索引 数组切片 改变维度 2. NumPy数组对象: NumPy中的ndarray是一个多维数组对象,该兑现共有两 ...

  5. Asp.NET CORE安装部署

    先安装IIS再安装这两个,不然后面各种bug HTTP 错误 500.19 代码 0x8007000d 解决方案 for win7_64 asp.net core IIS Web Core 1.比如最 ...

  6. logrus日志框架

    目录 logrus介绍 logrus配置 日志打印 HOOK机制 Gin日志 Fatal处理 线程安全 logrus介绍 golang标准库的日志框架非常简单,仅仅提供了print,panic和fat ...

  7. 剑指offer第40题

    package com.yan.offer; /** * 题目描述: * * 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. * * @author Ya ...

  8. 全天候式投资组合(All-weather Portfolio)

    此策略是美国知名对冲基金Bridgewater的负责人Ray Dalio长期研究的成果,其核心观点是将宏观因子,经济情景(economic scenario),和上文中提到的等风险权重(risk pa ...

  9. Ubuntu18.04 有线无法正常上网(请读完全文再进行操作)

    电脑Windows10+Ubuntu18.04双系统,一直都没问题,前段时间突然在Ubuntu系统下有线连接失败,但是在Windows下可以正常上网. 今天尝试进行了修复. 在终端通过ifconfig ...

  10. python 常用函数用法

    Assert 断言assert的语法其实有点像是fi 条件分支语句的“近亲”,assert这个关键字称为“断言”,当这个关键字后边的条件为false的时候,程序自动崩溃并抛出AssertionErro ...