King Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11946   Accepted: 4365 Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound kin…
BZOJ 差分约束: 我是谁,差分约束是啥,这是哪 太真实了= = 插个广告:这里有差分约束详解. 记\(r_i\)为第\(i\)行整体加了多少的权值,\(c_i\)为第\(i\)列整体加了多少权值,那么限制\((i,j),k\)就是\(r_i+c_j=k\). 这就是差分约束裸题了.\(r_i+c_j=k\Rightarrow r_i-(-c_j)\leq k\ \&\&\ -c_j-r_i\leq -k\). 注意形式是\(x_j-x_i\leq w\)=v= 建边跑最短路判负环即可.…
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根据套路,二分是显然的.然后跑一下spfa判断正环就行了. 然而我被no solution坑了十次提交.. #include <cctype> #include <cstdio> #include <cstring> using namespace std; const in…
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42366 Accepted: 15560 传送门 Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way p…
第一次看这个题目,完全不知道怎么做,看起来又像是可以建个图进行搜索,但题目条件就给了你几个不等式,这是怎么个做法...之后google了下才知道还有个差分约束这样的东西,能够把不等式化成图,要求某个点在满足所有不等式的情况下的最大取值,只需对建好的图进行一次最短路即可 不过要使得a b 点满足这样 a<=b+k这种不等式,还得对题目所给的不等式进行下改装 原不等式无非就是 输入个 si ni,使得存在 A(si)+...A(si+ni)<k 或者 >k,我们新定义一个s[],s[i]代表…
传送门 差分约束系统..找负环用spfa就行 ——代码 #include <cstdio> #include <cstring> #include <iostream> #define N 100001 int n, m, cnt; ], val[N << ], next[N << ], dis[N]; bool vis[N]; inline int read() { , f = ; char ch = getchar(); ; ) + (x &…
Code: #include<cstdio> #include<queue> #include<algorithm> using namespace std; const int N=300000+3; const int INF=-2333233; queue<int>Q; int d[N],inq[N],times[N]; int head[N],to[N<<1],val[N<<1],nex[N<<1]; int cn…
King Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14791   Accepted: 5226 Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound kin…
题目链接:http://poj.org/problem?id=3259 题目大意是给你n个点,m条双向边,w条负权单向边.问你是否有负环(虫洞). 这个就是spfa判负环的模版题,中间的cnt数组就是记录这个点松弛进队的次数,次数超过点的个数的话,就说明存在负环使其不断松弛. #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace st…
bfs版spfa void spfa(){ queue<int> q; ;i<=n;i++) dis[i]=inf; q.push();dis[]=;vis[]=; while(!q.empty()){ int u=q.front();q.pop(); for(int i=head[u];i;i=e[i].next){ int v=e[i].v,w=e[i].w; if(dis[v]>dis[u]+w){ dis[v]=dis[u]+w; if(!vis[v]){ vis[v]=;…