随笔分类 -  图论

摘要:poj 2186 Popular Cows强连通分量 tarjanhttp://poj.org/problem?id=2186#include <iostream>#include "stdio.h"#include "string.h"using namespace std;struct node{ int v, next;}edge[50000];const int MAXV = 10001;int adj[MAXV], lp, low[MAXV], dfn[MAXV], out[MAXV], belong[MAXV], stack[MA 阅读全文
posted @ 2011-08-17 14:24 Firecoder 阅读(147) 评论(0) 推荐(0)
摘要:经典的欧拉回路题http://poj.org/problem?id=1041欧拉回路:每条边经过一次且仅一次的称为欧拉回路(euler cycle, euler circuit)。存在欧拉回路的充要条件:每个点的度数都是偶数, 且图连通。#include "iostream"#include "stdio.h"#include "string.h"#include "algorithm"using namespace std;int G[50][2000]; //G[点][边] = 点,这样是为了能方便让边lexi 阅读全文
posted @ 2011-08-04 18:56 Firecoder 阅读(156) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1129四色定理#include "stdio.h"#include "iostream"#include "cstring"using namespace std;bool g[27][27];int color[27];bool dfs(int nColor, int now, int n) //nColor:所用颜色总数;now:当前待填颜色的物品的编号{ if(now > n) return true; for(int i = 1; i <= nColor; i+ 阅读全文
posted @ 2011-08-02 16:27 Firecoder 阅读(132) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1164提交的时候正遇oj挂了,害我白白错了几次,却不知情。。。#include "iostream"#include "stdio.h"#include "string.h"using namespace std;struct room{ bool vis; int val;}castle[51][51];int area;void dfs(int x, int y){ if(!castle[x][y].vis) { area++; castle[x][y].vis = true; 阅读全文
posted @ 2011-08-02 16:24 Firecoder 阅读(138) 评论(0) 推荐(0)
摘要:两道题都是求最小生成树的最长边。poj 2395 Out of Hay http://poj.org/problem?id=2395kruskal实现:#include "stdio.h"#include "string.h"#include "algorithm"#include "iostream"using namespace std;const int INF = 1e9, MAX = 2001;int fa[MAX];struct edge{ int s, e, val;};edge edges[1000 阅读全文
posted @ 2011-08-02 11:14 Firecoder 阅读(234) 评论(0) 推荐(0)
摘要:第一次写SPFA,小激动一下。。。http://poj.org/problem?id=1511#include "iostream"#include "stdio.h"#include "queue"#include "string.h"using namespace std;const int MAX = 1000010;const int INF = 1e9;struct edge{ int s, e; int val; int nextedge;};struct edge edges1[MAX], edges 阅读全文
posted @ 2011-08-02 09:58 Firecoder 阅读(105) 评论(0) 推荐(0)