Xzz is playing a MMORPG "human life".

In this game, there are N different skills. Some skills may base on another skill.

Learning skill will cost Xzz some money.

And there are M different jobs. If Xzz's skills satisfy the job's requirement, then Xzz can get this job, and get some money.

But some jobs are conflict, some Xzz can't get the job at same time.

There are K pairs of jobs are conflict.

Now Xzz want to know the money he can get at the most,can you help him.

Input

First line of the input file contains an integer T(0 < T ≤ 10) that indicates how many cases of inputs are there.

The description of each case is given below:

The first line of each input case contains number N, M, K. N <= 100, M <= 50, K <= 5.

Then follow N lines. In ith line the first two number ? ,? , means learning skill i const vi , skill i base on another ni skills. The last ni number aij means before learning skill i Xzz need to learn skill aij. 0 ≤ vi ≤ 1000, 0 ≤ ni ≤ N

Then follow M lines. In ith line the first two number wi, mi , means job i earn wi, jobs i base on mi skills. The last mi number bij means get job i need to learn skill bij. 0 ≤ wi ≤ 1000, 0 ≤ mi ≤ M

Then follow K lines. In ith line the first two number ci, di, means job ci conflict with job di.

Output

The description of output for each test case is given below:

The first line of the output for each test case contains number answer, the maximum money Xzz can get.

Sample Input

2
5 2 0
1 0
1 1 1
1 0
1 0
1 1 4
10 2 2 3
8 2 3 5
5 2 1
1 0
1 1 1
1 0
1 0
1 1 4
10 2 2 3
8 2 3 5
1 2

Sample Output

13
7 今天组队训练,这个我负责的图论部分没有写出来 难受啊
今天想拿网络流 流过去结果建图不知道该怎么建图 流也流不对
结束后才知道这就是最大权闭合子图的板子题目
唉 图论的基本套路我都还没有掌握 难受啊 今天然后晚上认真的学习了最大权闭合子图 点击这里学习最大权闭合子图 博主很良心讲的非常好 然后下面这一题就稍微的改动了一下
一开始我还在想k如何处理 ,后来学长告诉我k最大为5 直接枚举所有情况就好了 然后就是基本的建图操作
 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
using namespace std;
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define san(n,m) scanf("%d%d",&n,&m)
#define FIN freopen("in.txt","r",stdin)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
const int maxn = ;
typedef long long LL;
const int MX = ;
const int MXE = * MX * MX;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f;
struct MaxFlow {
struct Edge {
int v, nxt;
LL w;
} E[MXE];
int tot, num, s, t;
int head[MX];
void init() {
memset (head, -, sizeof (head) );
tot = ;
}
void add (int u, int v, LL w) {
E[tot] = (Edge) {
v, head[u], w
};
head[u] = tot++;
E[tot] = (Edge) {
u, head[v],
};
head[v] = tot++;
}
int d[MX], vis[MX], gap[MX];
void bfs() {
memset (d, , sizeof (d) );
memset (gap, , sizeof (gap) );
memset (vis, , sizeof (vis) );
queue<int>q;
q.push (t);
vis[t] = ;
while (!q.empty() ) {
int u = q.front();
q.pop();
for (int i = head[u]; ~i; i = E[i].nxt) {
int v = E[i].v;
if (!vis[v]) {
d[v] = d[u] + ;
gap[d[v]]++;
q.push (v);
vis[v] = ;
}
}
}
}
int last[MX];
LL dfs (int u, LL f) {
if (u == t) return f;
LL sap = ;
for (int i = last[u]; ~i; i = E[i].nxt) {
int v = E[i].v;
if (E[i].w > && d[u] == d[v] + ) {
last[u] = i;
LL tmp = dfs (v, min (f - sap, E[i].w) );
E[i].w -= tmp;
E[i ^ ].w += tmp;
sap += tmp;
if (sap == f) return sap;
}
}
if (d[s] >= num) return sap;
if (! (--gap[d[u]]) ) d[s] = num;
++gap[++d[u]];
last[u] = head[u];
return sap;
}
LL solve (int st, int ed, int n) {
LL flow = ;
num = n;
s = st;
t = ed;
bfs();
memcpy (last, head, sizeof (head) );
while (d[s] < num) flow += dfs (s, INFLL);
return flow;
}
} F;
int t, n, m, k, vis[];
struct node {
int val, n;
int num[];
} a[], b[];
struct node1 {
int x, y;
} p[maxn];
int main() {
scanf("%d", &t);
while(t--) {
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i <= n ; i++) {
scanf("%d%d", &a[i].val, &a[i].n);
for (int j = ; j < a[i].n ; j++) scanf("%d", &a[i].num[j]);
}
for (int i = ; i <= m ; i++) {
scanf("%d%d", &b[i].val, &b[i].n);
for (int j = ; j < b[i].n ; j++) scanf("%d", &b[i].num[j]);
}
for (int i = ; i < k ; i++) scanf("%d%d", &p[i].x, &p[i].y);
int st = , ed = n + m + ;
LL ans = ;
for (int i = ; i < ( << k) ; i++) {
LL sum = ;
F.init();
memset(vis, , sizeof(vis));
for (int j = ; j < k ; j++) {
if (vis[p[j].x] && vis[p[j].y] ) continue;
if ((i >> j) & ) vis[p[j].y] = ;
else vis[p[j].x] = ;
}
for (int j = ; j <= m ; j++) {
if (vis[j]) continue;
sum += 1LL * b[j].val;
F.add(st, j, b[j].val);
for (int p = ; p < b[j].n ; p++) F.add(j, m + b[j].num[p], INF);
}
for (int j = ; j <= n ; j++) {
F.add(m + j, ed, a[j].val);
for (int p = ; p < a[j].n ; p++) F.add(m + j, m + a[j].num[p], INF);
}
LL temp = F.solve(st, ed, n + m + );
ans = max(ans, sum - temp);
}
printf("%lld\n", ans);
}
return ;
}

Human life FZU - 2295 最大权闭合子图(第一次遇到被教育了)的更多相关文章

  1. FZU - 2295 Human life (最大权闭合子图)

    题目链接 FZU - 2295 Human life 题目分析 题意:你在玩一个游戏,在其中你可以通过学习一些技能,但是学习某些技能之前,可能还要学习一些其他的技能,并且学习任何技能都有一定的花费: ...

  2. FZU - 2295 Human life:网络流-最大权闭合子图-二进制优化-第九届福建省大学生程序设计竞赛

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 http://acm.fzu.edu.cn/problem.php?pid=2295 htt ...

  3. BZOJ1565 [NOI2009]植物大战僵尸(拓扑排序 + 最大权闭合子图)

    题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=1565 Description Input Output 仅包含一个整数,表示可以 ...

  4. HDU 3879 Base Station(最大权闭合子图)

    经典例题,好像说可以转化成maxflow(n,n+m),暂时只可以勉强理解maxflow(n+m,n+m)的做法. 题意:输入n个点,m条边的无向图.点权为负,边权为正,点权为代价,边权为获益,输出最 ...

  5. [BZOJ 1497][NOI 2006]最大获利(最大权闭合子图)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1497 分析: 这是在有向图中的问题,且边依赖于点,有向图中存在点.边之间的依赖关系可以 ...

  6. HDU4971 A simple brute force problem.(强连通分量缩点 + 最大权闭合子图)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4971 Description There's a company with several ...

  7. HDU5855 Less Time, More profit(最大权闭合子图)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5855 Description The city planners plan to build ...

  8. HDU5772 String problem(最大权闭合子图)

    题目..说了很多东西 官方题解是这么说的: 首先将点分为3类 第一类:Pij 表示第i个点和第j个点组合的点,那么Pij的权值等于w[i][j]+w[j][i](表示得分) 第二类:原串中的n个点每个 ...

  9. SCU3109 Space flight(最大权闭合子图)

    嗯,裸的最大权闭合子图. #include<cstdio> #include<cstring> #include<queue> #include<algori ...

随机推荐

  1. 【system.array】使用说明

    对象:system.array 说明:提供一系列针对数组类型的操作 目录: 方法 返回 说明 system.array.join( array, separator ) [String]  将数组转换 ...

  2. 【20180807模拟测试】tree

    题目描述 或许会传送失败的传送门 #分析 考虑如何才能让白边显得更(不)重要,即在每条白边上(加上)减去一个值. 我们可以二分这个值,然后用寻常方法做最小生成树.统计在此最小生成树里有多少白 边. 然 ...

  3. Android开发-API指南-<activity>

    <activity> 英文原文:http://developer.android.com/guide/topics/manifest/activity-element.html 采集(更新 ...

  4. CsvHelper文档-2读

    CsvHelper文档-2读 这个库默认不需要做任何设置就可以很容易的使用它.如果你的类属性名称直接匹配csv的标题名称,那么可以按照下面的实例来用: (以下所有的代码都需要引用using csvhe ...

  5. Shell 常用命令、基本用法总结

    Filter Filter 常用于从大量文本.数据中提取需求的部分.下面介绍几个常用的 filter 命令. cut $ cut -c 5-8 textfile.txt # 切出 textfile.t ...

  6. Period :KMP

    I - Period Problem Description For each prefix of a given string S with N characters (each character ...

  7. opencv-学习笔记(1)常用函数和方法。

    opencv-学习笔记(1)常用函数和方法. cv2.imread(filename,falg) filename是文件名字 flag是读入的方式 cv2.MREAD_UNCHANGED :不进行转化 ...

  8. Python3 Tkinter-OptionMenu

    1.创建 from tkinter import * root=Tk() v=StringVar() v.set('xs') om=OptionMenu(root,v,'Python','PHP',' ...

  9. 有关WCSF的几点整理

    本文示例代码 一.CreateNew Attribute实现属性注入 Steps: 1/ aspx创建某个服务的属性. 2/ 为其添加[CreateNew] Attribute. 3/ 页面继承自Mi ...

  10. apache不解析php文件遍历目录

    程序目录下有index.php缺不能正常解析,直接刷出整个目录. 解决:在后面添加index.php的解析即可.. DirectoryIndex index.html index.html.var i ...