sgu272:Evacuation plan(大水题)
来源:互联网 发布:域名转入自己的服务器 编辑:程序博客网 时间:2024/05/01 07:22
题目大意:
分析:
AC code:
#include <cstdio>#include <cmath>#include <cstdlib>#include <cstring>#include <cctype>#include <algorithm>#include <string>#include <sstream>#include <iostream>#include <map>#include <set>#include <list>#include <stack>#include <queue>#include <vector>#define pb push_back#define mp make_pairtypedef long long LL;typedef double DB;typedef long double LD;using namespace std;const int MAXN = 10009;const int MAXM = 220009;const int INF = 0x3f3f3f3f;int n, m;int n1, n2;int s, t;struct Ugraph{ int size; int head[MAXN]; int d[MAXM]; int to[MAXM]; int ne[MAXM]; Ugraph() {size = 1;} void add_edge(int u, int v) { to[size] = v, ne[size] = head[u], head[u] = size++; to[size] = u, ne[size] = head[v], head[v] = size++; }}G;int dis[MAXN];bool vis[MAXN];vector< vector<int> > ans; void spfa(int s){ queue<int> q; memset(dis, INF, sizeof dis); memset(vis, false, sizeof vis); q.push(s), dis[s] = 0, vis[s] = true; while(!q.empty()) { int now = q.front(), to; q.pop(), vis[now] = false; for(int i = G.head[now]; i; i = G.ne[i]) { to = G.to[i]; if(dis[to] > dis[now]+1) { dis[to] = dis[now]+1; if(!vis[to]) { vis[to] = true; q.push(to); } } } }}vector<int> cur;bool dfs(int x){ if(x == t) { ans.pb(cur); return true; } if(x != s && x != t) { cur.pb(x); vis[x] = true; } for(int i = G.head[x]; i; i = G.ne[i]) { int y = G.to[i]; if(dis[x]+1 == dis[y] && !vis[y]) { if(dfs(y) && x != s) { cur.pop_back(); return true; } } } cur.pop_back(); return false;}int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif scanf("%d%d", &n, &m); s = n+1, t = s+1; for(int i = 1; i <= m; ++i) { int u, v; scanf("%d%d", &u, &v); G.add_edge(u, v); } scanf("%d", &n1); for(int i = 1; i <= n1; ++i) { int x; scanf("%d", &x); G.add_edge(s, x); } scanf("%d", &n2); for(int i = 1; i <= n2; ++i) { int x; scanf("%d", &x); G.add_edge(x, t); } spfa(s); memset(vis, false, sizeof vis); dfs(s); printf("%d %d\n", ans.size(), dis[t]-2); for(int i = 0, sz = ans.size(); i < sz; ++i) { printf("%d", ans[i][0]); for(int j = 1; j < dis[t]-1; ++j) printf(" %d", ans[i][j]); puts(""); } #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0;}
0 0
- sgu272:Evacuation plan(大水题)
- Evacuation Plan
- hdu 3757 Evacuation Plan
- UVALive 4987 Evacuation Plan
- UVA 1474 Evacuation Plan
- HDU 3757 Evacuation Plan
- UVALive - 4987 Evacuation Plan
- POJ-2175-Evacuation Plan
- ZOJ 1553 Evacuation Plan
- UVA 1474 Evacuation Plan
- POJ 2175 Evacuation Plan
- HDU-3757-Evacuation Plan
- uva 1474 - Evacuation Plan(dp)
- POJ 3963 Evacuation Plan dp
- UVA 1474 Evacuation Plan(dp)
- POJ 2175 Evacuation Plan 笔记
- *POJ 2175 Evacuation Plan | 费用流
- POJ 2175 Evacuation Plan 消圈定理
- CodeForces#round308C解题报告
- github代码搜索技巧
- 减速器上盖
- Git在Eclipse上的应用--Egit插件--(一)
- Android背景渐变色(shape,gradient)
- sgu272:Evacuation plan(大水题)
- java基础--如何创建一个线程
- DOS命令大全(经典收藏)
- 管中窥探java虚拟机(一)
- 开始学习 ActiveMQ(1)
- N-Queens
- 代码规范初体验
- linux网络编程之二-----多播(组播)编程
- android dialog的使用