Orz hxyqwq, yinhee, yizhixiaoyun(🍺);|

WRuperD

园龄:3年3个月粉丝:8关注:12

solution-at-abc133-e

乱搞。

考虑对于每个点,它能染的颜色色的数量的限制是任何两个距离不大于 2 的不同节点。考虑直接按 dfs 序顺序染色。不用考虑每个点到底染了什么颜色,显然答案至与和它距离不大于 2 的不同节点已有多少个被染了色有关。直接任意钦定一种顺序跑一遍即可。

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
const int MAX = 1e5+10;
const int mod = 1e9 + 7;
vector <int> g[MAX];
int n, k;
bool f[MAX];
int hh[MAX];
int ans = 1;
void dfs(int u, int fa){
int cnt = 0;
for(int v:g[u]){
if(f[v]) cnt += hh[v], hh[u]++;
else{
continue ;
}
}
f[u] = 1;
hh[u] ++;
ans *= k - cnt;
ans %= mod;
for(int v:g[u]){
if(v == fa) continue;
dfs(v, u);
hh[u]++;
}
}
void solve(){
n = read(), k = read();
for(int i = 1; i < n; i++){
int u = read(), v = read();
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 1);
write(ans), endl;
}
signed main(){
int t = 1;
while(t--) solve();
return 0;
}

本文作者:WRuperD

本文链接:https://www.cnblogs.com/WRuperD/p/18001941

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   WRuperD  阅读(8)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现

本文作者:DIVMonster

本文链接:https://www.cnblogs.com/guangzan/p/12886111.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

这是一条自定义内容

这是一条自定义内容

西雅图

点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 Imagine John Lennon
  2. 2 海阔天空 Beyond
  3. 3 Iridescent Linkin Park
  4. 4 New Devide Linkin Park
  5. 5 Bohemian Rhapsody Queen
  6. 6 夜的第七章 周杰伦
  7. 7 夜曲 (Live) 周杰伦
  8. 8 七里香 丐版
  9. 9 止战之殇 (Live) 周杰伦
  10. 10 We Are The World U.S.A. For Africa
  11. 11 So Far Away (Acoustic) Adam Christopher
夜的第七章 - 周杰伦
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

Not available