# hihoCoder1252 2015北京区域赛 D.Kejin Game

1.对于每个技能i，将它拆成标号为i和n+i的两个点，从i向n+i连边，容量为强行氪出这个技能的花费；

2.对于强行去掉前置条件，比如a是b的前置这个条件，从n+a向b连边，容量为去掉这个技能的花费；

3.建个源点，标号为0好了~对于每个技能，连一条从0到i的边，容量为用通常方法学习这个技能的花费；

4.设目标技能是第j号技能，从n+j向汇点连边，容量为INF；

5.跑一边最大流就ok了。

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cctype>

#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<set>
#include<algorithm>
#include<stack>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
const int INF = 0x7fffffff;
typedef long long ll;
const double eps = 1e-8;
const double PI = 2 * cos(0.0);
const int MOD = 1000000007;

#define MAXN 100001

int T, n, m, s, x, y, z, cnt;
int gap[MAXN], level[MAXN], cur[MAXN];

struct Node
{
int v, cap, next;
Node(){}
Node(int v, int cap, int next) :v(v), cap(cap), next(next){}
}Edge[MAXN];

void AddEdge(int u, int v, int cap)
{
}

int ISAP(int vs, int vt, int n)
{
int res = 0;
for (int i = 0; i<n; i++)
pre[vs] = vs;
gap[0] = n;
int aug = INF;
int u = vs;
for (; level[vs] < n;)
{
bool flag = 0;
for (int i = cur[u]; i != -1; i = Edge[i].next)
{
int v = Edge[i].v;
if (Edge[i].cap && level[u] == level[v] + 1)
{
flag = 1;
pre[v] = u;
cur[u] = i;
u = v;
aug = min(aug, Edge[i].cap);
break;
}
}
if (!flag)
{
int mh = n;
for (int i = head[u]; i != -1; i = Edge[i].next)
{
int v = Edge[i].v;
if (Edge[i].cap && level[v] < mh)
{
mh = level[v];
cur[u] = i;
}
}
if (!--gap[level[u]]) break;
gap[level[u] = mh + 1]++;
u = pre[u];
}
else if (u == vt)
{
for (; u != vs; u = pre[u])
{
int v = pre[u];
Edge[cur[v]].cap -= aug;
Edge[cur[v] ^ 1].cap += aug;
}
res += aug, aug = INF;
}
}
return res;
}

int main()
{
cin >> T;
while (T--)
{
cin >> n >> m >> s;
mem(gap, 0);
mem(pre, -1);
mem(level, 0);
cnt = 0;
for (int i = 0; i < m; i++)
{
scanf("%d%d%d", &x, &y, &z);
}
for (int i = 1; i <= n; i++)
{
scanf("%d", &x);
}
for (int i = 1; i <= n; i++)
{
scanf("%d", &x);
}

AddEdge(n + s, n + n + 1, INF);
cout << ISAP(0, n + n + 1, n + n + 2) << endl;
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：hihoCoder1252 2015北京区域赛 D.Kejin Game 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)