#include<iostream>//没什么好说的按照刘汝佳的书写就好了,挺简单的。。
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int n,a[30][30];
struct edgee
{
int to, cap;
};
edgee edge[8000];
int first[2000], nextt[8000],d[2000],change[2000];
int edgetot;
int win[100], defeat[100];
vector<int>team;
void addedge(int from, int to, int cap)
{
edge[edgetot].to = to;
edge[edgetot].cap = cap;
nextt[edgetot] = first[from];
first[from] = edgetot;
edgetot++;
edge[edgetot].to = from;
edge[edgetot].cap = 0;
nextt[edgetot] = first[to];
first[to] = edgetot;
edgetot++;
}
bool bfs(int s,int t)
{
for (int i = 0; i <= n + n*n + 2; i++)d[i] = -1;
d[s] = 0;
queue<int>que;
que.push(s);
while (!que.empty())
{
int temp = que.front();
if (temp == t)return true;
que.pop();
for (int i = first[temp]; i != -1; i = nextt[i])
{
int to = edge[i].to;
if (d[to] == -1 && edge[i].cap)
{
d[to] = d[temp] + 1;
que.push(to);
}
}
}
return false;
}
int dfs(int x, int t, int flow)
{
if (x == t || flow == 0)
return flow;
int allflow = 0;
for (int &i = change[x]; i != -1; i = nextt[i])
{
int to = edge[i].to;
if (d[to] == d[x] + 1 && edge[i].cap)
{
int tempflow = dfs(to, t, min(flow, edge[i].cap));
flow -= tempflow; allflow += tempflow;
edge[i].cap -= tempflow; edge[i ^ 1].cap += tempflow;
if (flow == 0)break;
}
}
if (allflow == 0)d[x] = -1;
return allflow;
}
int dicnic(int s, int t, int fini)//这题对流没有限制,求出最大流就好
{
int allflow = 0;
while (bfs(s, t))
{
for (int i = 0; i <= n*n + n + 1; i++)change[i] = first[i];
allflow += dfs(s, t, 1000000000);
}
return allflow;
}
bool control(int num, int ww)
{
int wnum = ww;
for (int i = 1; i <= n; i++)
{
wnum += a[num][i];
}
edgetot = 0;
int diantot = n; int sum = 0;
for (int i = 0; i <= n*n + n + 1; i++)first[i] = -1;
for (int i = 1; i <= n; i++)
{
if (i == num)continue;
if (wnum - win[i] < 0)return false;
addedge(i, n + n*n + 1, wnum - win[i]);
}
for (int i = 1; i <= n; i++)
{
if (i == num)continue;
for (int j = i + 1; j <= n; j++)
{
if (j == num)continue;
diantot++;
sum += a[i][j];
addedge(0, diantot, a[i][j]);
addedge(diantot, i, 1000000000);
addedge(diantot, j, 1000000000);
}
}
int q=dicnic(0, n*n + n + 1,1000000000);
return q == sum;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
team.clear();
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d %d", &win[i], &defeat[i]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
if (control(i, win[i]))
team.push_back(i);
for (int i = 0; i < team.size(); i++)
{
if (i != team.size() - 1)
printf("%d ", team[i]);
else
printf("%d\n", team[i]);
}
}
return 0;
}
09-27
07-01
07-01
07-01
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交