https://www.cnblogs.com/tyqtyq/p/9769817.html


0x65

负环

  • SPFA
  • 当一个节点入队次数到达N的时候,就说明有负环
  • 或者记录最短路包含的路径条数
  • 还有其他优化手段,如将SPFA的队列换成栈,使用dfs等等

差分约束系统

  • 特殊的不等式组,有N个不等式
  • 任意不等式都是形如这样的:\(X_{i} - X_{j} \leq c_{k}\)
  • 我们就可以建一张图使得对于任意不等式\(X_{i} - X_{j} \leq c_{k}\),在i,j之间连一条长度为\(c{k}\)的边
  • 那么我们求解单源最短路,\(X_{i} = dist_{i}\)就是一组解
  • 但是为了保证图的联通性,应该加一个虚拟节点\(X_{0}\)使得其到所有节点距离为0,从\(X_{0}\)开始跑SPFA就可以求出解了
  • 如果有负环则无解

0x66

卡了我几天的tarjan算法QAQ

tarjantql!

  • 深搜一遍求出时间戳
  • 定义一个追溯值\(low_{x}\)为\(min{\{i|i \in \{ {a|a \in subtree(x) || a \in } }{a可通过一条不在搜索树上的边到达subtree(x)中的节点\} \}}\)
  • 那么珂以通过一遍dfs搜出dfn和low数组
  • 接下来讲讲如何判定是否是割点/边:

割边判定:边(x,y)是割边当且仅当\(dfn_{x} \le low_{y}\)

  • 直接根据定义yy一下即可
  • 无向图需要处理一下重边个数问题:
  • 当fa为x的父亲的时候,如果有重边则珂以用来更新
  • 珂以用成对变换解决

割点判定:

  • 对于不是搜索树根节点点x,若存在一x的子节点y使得\(dfn_{x} \leq low_{y}\),则x是割点
  • 如x为根节点,则需要两个这样的y
  • 割点为\(\leq\),不需考虑父节点与重边

缩点

  • 定义:若一个无向图没有割点,则称其为点双联通图,同理我们称没有割边的图为边双联通图
  • 无向图的极大双联通子图被称为点双联通分量,边同理

我trl跳过无向图tarjan缩点


好吧我图论渣渣就是没办法,放了放了,先搞Dp和数据结构,以后再来填这个坑

I'm BACK!

JZOJ图论好题

3936. 【GDOI2015模拟11.22】假期计划

观察到k很小,珂以对所有k执行dijkstra求出最短路,时间复杂度O(KNlgN)

对于一次询问(x,y),先暴力枚举一遍所有枢纽,设枚举到枢纽i,计算(x->i->y)的最短路,珂以O(1)求出

时间复杂度O(KNlgN+QM),卡卡常就珂以通过此题

/*
Copyright(c) TYQ
All rights served;
*/
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#define MAXN 20005
#define MAXM 20005
#define MAXK 205
#define MAXQ 50005
using namespace std;
int edge[MAXM],ver[MAXM],Next[MAXM],head[MAXN],temp[MAXK] ;
int d[MAXK][MAXN];
bool v[MAXQ],intemp[MAXN] ;
int N,K,M,Query,tot,sum,num ;
void add(int x,int y,int z){
edge[++tot]=z,ver[tot]=y,Next[tot]=head[x],head[x]=tot ;
}
priority_queue<pair<int,int> > q;
void dijkstra(int start){
while(q.size())q.pop() ;
memset(v,0,sizeof(v)) ;
d[start][start]=0;
q.push(make_pair(d[start][start],start)) ;
while(q.size()){
int x = q.top().second ;
q.pop() ;
if(v[x])continue ;
v[x]=true ;
for(int i = head[x]; i;i = Next[i]){
int y = ver[i] , z = edge[i] ;
if(d[start][y] > d[start][x] + z){
d[start][y] = d[start][x] + z ;
q.push(make_pair(-d[start][y],y)) ;
}
}
}
}
int main(){
memset(d,0x3f,sizeof(d));
scanf("%d%d%d%d",& N,& M,& K,& Query) ;
for(int i=1;i<=M;++i){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
add(x,y,z) ;
}
for(int i=1;i<=K;++i){
scanf("%d",& temp[i]) ;
intemp[temp[i]] = true;
dijkstra(temp[i]) ;
//for(int j=1;j<=N;++j)printf("%d ",d[temp[i]][j]) ;printf("\n") ;
}
while(Query--){
int x,y;
scanf("%d%d",&x,&y) ;
int minv = 0x7f7f7f7f ;
for(int i=head[x]; i;i=Next[i]){
//printf("(%d,%d)\n",i,ver[i]) ;
if(intemp[ver[i]])minv = min(minv,edge[i]+d[ver[i]][y]) ;
}
if(minv!=0x7f7f7f7f)sum+=minv,++num/*,printf("can\n")*/ ;
}
printf("%d\n%d\n",num,sum);
return 0;
}

Warning!

本文由 TYQ 创作,采用 知识共享署名 4.0 国际许可协议进行许可。
转载要与作者联系,并需在正文明显处署名作者且注明文章出处。
对了,我永远喜欢C++啊。

Graph & Tree2的更多相关文章

  1. [开发笔记] Graph Databases on developing

    TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...

  2. Introduction to graph theory 图论/脑网络基础

    Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...

  3. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  4. [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  5. [LeetCode] Graph Valid Tree 图验证树

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  6. [LeetCode] Clone Graph 无向图的复制

    Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...

  7. 讲座:Influence maximization on big social graph

    Influence maximization on big social graph Fanju PPT链接: social influence booming of online social ne ...

  8. zabbix利用api批量添加item,并且批量配置添加graph

    关于zabbix的API见,zabbixAPI 1item批量添加 我是根据我这边的具体情况来做的,本来想在模板里面添加item,但是看了看API不支持,只是支持在host里面添加,所以我先在一个ho ...

  9. Theano Graph Structure

    Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...

随机推荐

  1. vue学习(十一)vue-cli3开发单文件组件

    一 单文件组件介绍 二 如何安装Vue-Cli3脚手架 三 快速原型开发 四 vue-cli3生成项目 五 购物车项目搭建 六 购物车项目操作 七 Mock模拟数据 八 Vue中使用第三方组件(ele ...

  2. 【pwnable.kr】bof

    pwnable从入门到放弃,第三题. Download : http://pwnable.kr/bin/bofDownload : http://pwnable.kr/bin/bof.c Runnin ...

  3. 封装localStorage设置,获取,移除方法

    export const local = { set(key, value) { localStorage.setItem(key, JSON.stringify(value)); }, get(ke ...

  4. cf 453A.Little Pony and Expected Maximum

    水了一上午.. 拿6面举例子吧,因为是投掷m次取最大,最大是1概率(1/6)^m;最大是2就可以取到(1,2)那么概率就是(1/3)^m-(1/6)^m.(当前减去上一个) #include<b ...

  5. 量化投资_Multicharts数组操作函数_zeros()设定数组元素为0(自定义)

    1. 函数的用法类似于Python的zeros函数,给定数组尺寸,让数组的元素归零 //zeros:根据设定的尺寸长度,让一维数组的元素全部归零 inputs: arr[MaxSize]( numer ...

  6. 微服务基础——厉害了!API网关

    微服务刚刚诞生的时候,人们将服务进行拆分,实现服务之间的松耦合,并且每个服务有专门的团队维护,然后客户端直接和各个子服务进行交互.比如,订单,商品,会员服务. 那么这种客户端直接和后端服务交互的方式会 ...

  7. VS2013的工程移植到VS2008

    VS2013的工程完成后,用VS2008创建一个名称一样的工程(大小写也一样). 具体过程参考http://blog.csdn.net/sz76211822/article/details/42775 ...

  8. 18 11 27 高级的服务器连接 epoll

    ---恢复内容开始--- 之前的  http 服务器  都是采用 轮询的方式(就像 厨师挨个问谁饿了好做饭 一样  ) 而  epoll 用着高级的 方式  事件通知 (直接问谁饿了) 同时还和  计 ...

  9. Delphi流的操作_文件合并

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  10. LeetCode 543. Diameter of Binary Tree 二叉树的直径 (C++/Java)

    题目: Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of ...