首页 > 在树上游玩
头像 一个与众不同的字节
发表于 2025-04-15 23:18:04
感觉主要难点在于题意理解,其实就是图的遍历。把连通的标记节点视为一个连通块,每个连通块只需要染色一条边,总方案数为每个连通块相邻节点数的连乘,最小代价为连通块数量。 #include <iostream> #include <vector> using namespace s 展开全文
头像 977ust
发表于 2025-04-04 18:55:46
#include <iostream> #include <vector> using namespace std; int main() { // int n,k; cin >> n >> k; // denot 展开全文
头像 977ust
发表于 2025-04-04 19:22:14
#include <iostream> #include <vector> using namespace std; int main() { // int n,k; cin >> n >> k; // denot 展开全文
头像 牛客856751393号
发表于 2025-03-14 16:01:37
from sys import stdin from collections import defaultdict # 计算从某个被标记的节点出发,不需要染色就能够到达的未被标记节点的数量 def dfs(node, parent): # (当前访问的节点, 当前节点的父节点) vis 展开全文
头像 牛客193507862号
发表于 2025-07-16 01:21:22
import sys from collections import deque # 最小染色数量,为红线(两个标记点有相连)的数量 # 方案数量,是与红线有相连的未染色边的数量,并除以模MOD # 由于染色方案数量可能很大,请输出对10^9+7取模后的结果 MOD = 10 ** 9 + 7 展开全文
头像 emo的钝角天天摸鱼
发表于 2025-03-17 21:23:15
#include <iostream> #include <bits/stdc++.h> using namespace std; #define int long long unordered_map<int,int> mp1,mp2; // mp1记录节点 展开全文
头像 牛客193507862号
发表于 2025-07-15 03:05:50
import sys from collections import deque # 由于染色方案数量可能很大,请输出对10^9+7取模后的结果 MOD = 10 ** 9 + 7 def main(): input_l = sys.stdin.read().split() # 输 展开全文
头像 Goldminer
发表于 2025-04-25 10:49:56
#include <iostream> #include <vector> using namespace std; typedef long long LL; const int MOD = 1e9 + 7; const int maxn = 200005; bool vi 展开全文
头像 番禺小韭菜
发表于 2025-03-06 11:57:42
#include <cstdint> #include <iostream> #include <vector> using namespace std; int main() { constexpr int MOD = 1e9 + 7; // 展开全文
头像 牛客193507862号
发表于 2025-07-15 14:47:03
import sys from collections import deque # 由于染色方案数量可能很大,请输出对10^9+7取模后的结果 MOD = 10 ** 9 + 7 def main(): input_l = sys.stdin.read().split() # 输 展开全文

等你来战

查看全部