摘要: 换根dp 描述: 题目初始不给出根节点,需要以每一个节点为根节点遍历,打到某一个根节点的最佳情况。 暴力的思路是循环每个节点做为根节点,同时在遍历整个树,时间复杂度是O(n^2) 换根dp主要是将时间复杂度降到O(n),在根节点切换时,直接通过一些已经计算过的数据在O(1)就能得到另一个根的结果。 阅读全文
posted @ 2024-04-12 11:04 contiguous 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 线段覆盖:https://ac.nowcoder.com/acm/contest/78292/F 涂色求结果,https://atcoder.jp/contests/abc346/tasks/abc346_e,这种过程有关于颜色求最后结果,考虑从后往前推 多项式:https://ac.nowcode 阅读全文
posted @ 2024-03-25 20:06 contiguous 阅读(4) 评论(0) 推荐(0) 编辑
摘要: ABC344 A - Spoiler 题意: 给出一个字符串,串中有两个$|$,输出$|$两边的内容。 思路: 我写的代码非常丑陋,模拟写的。 赛后看到string的stl,感觉非常妙。 rfind(str)是从字符串右侧开始匹配str #include<bits/stdc++.h> using n 阅读全文
posted @ 2024-03-20 22:51 contiguous 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 瑞士轮 思路: 快排会g,所以要归并排序 define int long long会g,关掉 快排函数: stable_sort,用法和sort一样 #include <bits/stdc++.h> using namespace std; // #define int long long stru 阅读全文
posted @ 2024-03-09 22:54 contiguous 阅读(13) 评论(0) 推荐(0) 编辑
摘要: include <bits/stdc++.h> using namespace std; define int long long vector<array<int, 5>> adj[1000005]; void solve() { int n, m; cin >> n >> m; for (int 阅读全文
posted @ 2024-03-03 19:18 contiguous 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 要开学了 ABC341 A - Print 341 题意: 输出n个10最后输出1 #include <bits/stdc++.h> using namespace std; #define int long long void solve() { int n; cin >> n; for (int 阅读全文
posted @ 2024-02-24 14:55 contiguous 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 今天学习一下缩点。 强连通的蓝题真水 luogu p2812 题意: 学校有n台计算机,他们之间有线路相连,我们视为有向边。 (1)问要使得所有计算机都能获取到一个消息,需要几台母机? (2)如果用一台母机传播消息使得所有计算机都接收到,需要添加几条新的线路? 思路: 这个题是缩点的模板题。 首先通 阅读全文
posted @ 2024-02-20 23:23 contiguous 阅读(6) 评论(1) 推荐(0) 编辑
摘要: div4怎么只能出5个(我是🤡) codeforce928 A - Vlad and the Best of Five 题意: 看A和B的数量谁多。 #include <bits/stdc++.h> using namespace std; #define int long long void s 阅读全文
posted @ 2024-02-20 00:48 contiguous 阅读(27) 评论(0) 推荐(0) 编辑
摘要: 先来强化一下强连通分量 luogu P1407 [国家集训队] 稳定婚姻 题意: 给n对现在的夫妻和m对曾经相爱的人。 如果有一对夫妻分开了,有没有可能这两个人和另外的几对夫妻组成新的组合。 如果可能输出‘unsafe’,否则输出‘safe’ 思路: 看完题之后我懵了,我看了一眼题解描述的题意才明白 阅读全文
posted @ 2024-02-18 23:43 contiguous 阅读(14) 评论(0) 推荐(1) 编辑
摘要: 想开学了 强连通分量模板 #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int>e[N]; int dfn[N], low[N], tot; int stk[N], instk[N], top; 阅读全文
posted @ 2024-02-17 23:59 contiguous 阅读(8) 评论(0) 推荐(0) 编辑