
图论
_Yyg
这个作者很懒,什么都没留下…
展开
-
hdu 4635 Strongly connected (强连通分量)
思路:最终添加完边的图,肯定可以分成两个部X和Y,其中只有X到Y的边没有Y到X的边,那么要使得边数尽可能的多,则X部肯定是一个完全图,Y部也是,同时X部中每个点到Y部的每个点都有一条边,假设X部有x个点,Y部有y个点,有x+y=n,同时边数F=x*y+x*(x-1)+y*(y-1),整理得:F=N*N-N-x*y,当x+y为定值时,二者越接近,x*y越大,所以要使得边数最多,那么X部和Y部原创 2013-08-03 16:01:02 · 449 阅读 · 0 评论 -
hdu 4463 Outlets (次小生成树)
#include#include#include#includeusing namespace std;const int inf = 0x3f3f3f3f;int n , m , a , b , c;double map[105][105];double dist[105] , ans1 , ans2;int vis[105] , use[105][105] , p[20原创 2013-09-27 20:31:30 · 586 阅读 · 0 评论 -
uVA 10600 ACM Contest and Blackout (prim求次小生成树)
use标记当前边是否属于最小生成树。d[i][j]代表从i->j的瓶颈路。#include#include#includeusing namespace std;const int inf = 0x3f3f3f3f;int n , m , a , b , c;int map[105][105];int dist[105] , vis[105] , ans1 , an原创 2013-09-26 10:26:53 · 581 阅读 · 0 评论 -
HDU 4081 Qin Shi Huang's National Road System (次小生成树)
复习了一下次小生成树。。。。#include#include#include#includeusing namespace std;const int inf = 0x3f3f3f3f;int n , m , a , b , c;double map[1005][1005];double dist[1005] , ans1 , ans2;int vis[1005]原创 2013-10-04 13:03:08 · 469 阅读 · 0 评论 -
hdu 4725 The Shortest Path in Nya Graph (SPFA+SLF优化)
#include#include#include#includeusing namespace std;const int maxn = 100500;const int inf = 0x3f3f3f3f;int t , n , m , c , vis[maxn * 4] , cnt[maxn * 4] , dist[maxn * 4] , cc , a , b;struct原创 2013-09-17 17:57:34 · 508 阅读 · 0 评论 -
hdu 1874 畅通工程续 (SPFA模板)
#include#include#includeconst int maxn = 70010;const int inf = 0x3f3f3f3f;using namespace std;int vis[maxn] , cnt[maxn] , dist[maxn] , n , m , c , a , b;struct G{ int head[maxn] , e;原创 2013-09-12 20:28:33 · 485 阅读 · 0 评论 -
poj 1861 Network (kruskal 最小生成树)
#include#include#includeconst int maxn = 15005;int n , m , fa[maxn] , rank[maxn];struct T{ int u , v , c;}edge[maxn * 2] , edge1[maxn * 2];void init(){ for(int i = 1 ; i <= n ; i ++原创 2013-09-05 20:09:53 · 532 阅读 · 0 评论 -
hdu 3371 Connect the Cities (Kruskal+ 并查集)
#include#include#includeconst int maxn = 255003;int fa[maxn] , rank[maxn] , n , m , k , p , q , c , tot , head[maxn] , ans , cnt;struct T{ int u , v , c , next;}edge[maxn * 2];int cmp(原创 2013-09-05 19:36:37 · 445 阅读 · 0 评论 -
hdu 4587 TWO NODES
#include#include#includeusing namespace std;const int maxn = 5008;int head[maxn] , low[maxn] , pre[maxn] , depth , iscut[maxn] , instack[maxn];int n , m , e , a , b , ret , del;struct T{原创 2013-08-20 10:36:19 · 641 阅读 · 0 评论 -
poj 1236 Network of Schools (强连通分量+缩点)
思路:首先用tarjan算法算出每个点属于哪个连通块,再缩点后求出各个连通块的入度出度。 入度为0的点的个数就是问一的解。 入度和出度为0的点个数多的就是问二的解。代码:#include#include#include#includeusing namespace std;const int maxn = 119;int n , in[ma原创 2013-07-29 11:17:57 · 523 阅读 · 0 评论 -
UVa Fire! 11624 (BFS)
莫名其妙的 runtime error。代码:#include#include#include#define _n printf("\n");using namespace std;struct T{ int x; int y; int step;};int dir[5][5] = {{1 , 0} , {-1 , 0} , {0 , 1} , {0 , -1}};原创 2013-07-26 22:38:51 · 567 阅读 · 0 评论 -
hdu 4460 Friend Chains (BFS)
简单BFS#include#include#include#include#includeusing namespace std;const int maxn = 1005;int n , ans , e , m;int head[maxn] , vis[maxn];bool flag;struct T{ int u , v , next;}edge[m原创 2013-09-27 20:27:13 · 2216 阅读 · 0 评论