dfs
lll_564
这个作者很懒,什么都没留下…
展开
-
Codeforces661 E1. Weights Division(easy version)(贪心+优先队列)
题目链接 思路: 先计算每条边被计算的次数,然后贪心地每次减半能减少最多花费的边,直到小于等于S为止。 代码: #include<bits/stdc++.h> #define ll long long #define LL long long #define PB push_back #define MP make_pair using namespace std; const int maxn=2e5+100; const ll inf=1e18+10; ll n,s,val[maxn],le原创 2020-08-06 21:14:38 · 125 阅读 · 0 评论 -
2020杭电暑假多校第六场 A Very Easy Graph Problem(换根dp)
题目链接 **题意:**给一个无向图,每个点为0或1,第i条边长度为2的i次方。题目要求出所有点i、j,i为0且j为1,i、j间最短路的和。 **思路:**首先容易看出,若第i条边加入后图中产生了环,由于二进制的特性第i条边必然不能在最短路中,所以转化为树上问题。换根dp维护两个状态,1.每个节点到标记为1的子节点的路径长度和。2.每个节点标记为1的子节点个数。 代码: #include<bits/stdc++.h> #define ll long long #define LL long lo原创 2020-08-06 21:06:42 · 140 阅读 · 0 评论 -
Codeforces660 D. Captain Flint and Treasure(dfs贪心)
D. Captain Flint and Treasure Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure’s location or may not. That’s why captain Flint decided to leave the solving the problem原创 2020-08-01 00:36:48 · 143 阅读 · 0 评论 -
Codeforces660 C. Uncle Bogdan and Country Happiness(dfs模拟)
Uncle Bogdan and Country Happiness Uncle Bogdan is in captain Flint’s crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and n−1 undirected roads connecting原创 2020-08-01 00:27:51 · 173 阅读 · 0 评论