D - Fedor Runs for President 思路: 推出斜率优化公式后,会发现最优点只可能来自凸斜率中的第一个元素和最后一个元素, 这两个元素不用维护凸斜率也能知道,就是第一个和上一个元素 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define y1 y11 #define fi…
Codeforces 思路 考虑把连的那两个点中间的链提出来,那么就会变成一条链,链上的每个点挂着一棵子树的形式. 设那些子树的大小为\(S_1,S2,\cdots\),那么新加的简单路径个数就是 \[ \frac 1 2 (n^2-\sum S^2) \] 很容易理解:任意两个点,只要不在同一棵子树内,就会多一条路径. 那么就可以树形DP:设\(dp_x\)表示从\(x\)向下连的一条链,\(\sum S^2\)的最小值,也很容易转移. 但是统计答案,也就是把两条链连在一起的时候,怎么办呢?…
E. President and RoadsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/problem/E Description Berland has n cities, the capital is located in city s, and the historic home town of the President is in city t (s ≠ t). The c…
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard output All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket hav…
题目链接: http://codeforces.com/contest/567/problem/E 题意: 给你一个带重边的图,求三类边: 在最短路构成的DAG图中,哪些边是必须经过的: 其他的(包括不在DAG上的边)不是必须经过的边把权值改小多少才能通过, 或者根本不可能通过的. 题解: 从起点s跑一遍最短路得到d[maxn],从终点t跑一遍最短路得到d2[maxn],对于边(u,v,w),如果d[u]+d2[v]+w==d[t]那么这条边在最短路上,对于不在最短路上的边,如果d[u]+d2[…
Codeforces 467 D 题意:给\(m​\)个单词,以及\(n​\)个置换关系,问将\(m​\)个单词替换多次后其中所含的最少的\(R​\)的数量以及满足这个数量的最短总长度 思路:首先将置换关系构图,然后进行强连通分量分解,为每一个强连通分量保存最小的答案,然后\(dp​\)把一个子\(dag​\)的答案求出即可. \(wa\)了\(3\)次,前\(2\)次是因为\(tarjan\)写错了,另一次是因为没开\(long\ long\).…
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume…
图给得很良心,一个s到t的有向图,权值至少为1,求出最短路,如果是一定经过的边,输出"YES",如果可以通过修改权值,保证一定经过这条边,输出"CAN",并且输出最小修改值,否则输出"NO".保证有s到t的路径,可能有重边. 建正反两个图,分别求出s和t的最短路径,用来判断一条边是不是在最短路径上,然后把最短路径取出来建一个图求割边. 不要用spfa,最坏O(VE),(出卡spfa数据的方法:Hard Test),会TLE 109(数据好啊),自…
Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作时队首两个数. 显然\(O(n)\)次以内队首变成了最大值,之后就循环了,暴力前\(O(n)\)个操作的答案即可 https://codeforces.com/contest/1179/submission/55878330 CF1179B Tolik and His Uncle 有一个\(n*m\…
B. President's Office 题目连接: http://codeforces.com/contest/6/problem/B Description President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a un…