Problem 1124 - Football Coach
Time Limit: 2000MS
Memory Limit: 65536KB
Total Submit: 332 Accepted: 153 Special Judge: No
Total Submit: 332 Accepted: 153 Special Judge: No
Description
It is not an easy job to be a coach of a football team. The season is almost over, only a few matches are left to play. All of sudden the team
manager comes to you and tells you bad news: the main sponsor of your club is not happy with your results and decided to stop sponsoring your
team, which probably means the end of your club. The sponsor's decision is final and there is no way to change it unless... unless your team
miraculously wins the league.
The manager left you in deep thought. If you increase the number of practices and offer players a generous bonus for each match, you may be
able to win all the remaining matches. Is that enough? You also have to make sure that teams with many points lose against teams with few
points so that in the end, your team will have more points than any other team. You know some of the referees and can bribe them to manipulate
the result of each match. But first you need to figure out how to manipulate the results and whether it is possible at all.
There are N teams numbered 1 through N, your team has the number N. The current number of points of each team and the list of remaining
matches are given. Your task is to find out whether it is possible to manipulate each remaining match so that the team N will finish with
strictly more points than any other team. If it is possible, output "YES", otherwise, output "NO". In every match, the winning team gets 2
points, the losing team gets 0. If the match ends with a draw, both teams get 1 point.
manager comes to you and tells you bad news: the main sponsor of your club is not happy with your results and decided to stop sponsoring your
team, which probably means the end of your club. The sponsor's decision is final and there is no way to change it unless... unless your team
miraculously wins the league.
The manager left you in deep thought. If you increase the number of practices and offer players a generous bonus for each match, you may be
able to win all the remaining matches. Is that enough? You also have to make sure that teams with many points lose against teams with few
points so that in the end, your team will have more points than any other team. You know some of the referees and can bribe them to manipulate
the result of each match. But first you need to figure out how to manipulate the results and whether it is possible at all.
There are N teams numbered 1 through N, your team has the number N. The current number of points of each team and the list of remaining
matches are given. Your task is to find out whether it is possible to manipulate each remaining match so that the team N will finish with
strictly more points than any other team. If it is possible, output "YES", otherwise, output "NO". In every match, the winning team gets 2
points, the losing team gets 0. If the match ends with a draw, both teams get 1 point.
Input
There will be multiple test cases. Each test case has the following form: The first line contains two numbers N(1 <= N <= 100) and M(0 <= M <=
1000). The next line contains N numbers separated by spaces giving the current number of points of teams 1, 2, ..., N respectively. The
following M lines describe the remaining matches. Each line corresponds to one match and contains two numbers a and b (a not equal to b, 1 <=
a,b <= N) identifying the teams that will play in the given match. There is a blank line after each test case.
1000). The next line contains N numbers separated by spaces giving the current number of points of teams 1, 2, ..., N respectively. The
following M lines describe the remaining matches. Each line corresponds to one match and contains two numbers a and b (a not equal to b, 1 <=
a,b <= N) identifying the teams that will play in the given match. There is a blank line after each test case.
Output
For each test case, output "YES" or "NO" to denote whether it's possible to manipulate the remaining matches so that the team N would win
the league.
the league.
Sample Input
5 8
2 1 0 0 1
1 2
3 4
2 3
4 5
3 1
2 4
1 4
3 5
5 4
4 4 1 0 3
1 3
2 3
3 4
4 5
2 1 0 0 1
1 2
3 4
2 3
4 5
3 1
2 4
1 4
3 5
5 4
4 4 1 0 3
1 3
2 3
3 4
4 5
Sample Output
YES
NO
题意:有n只球队,m场比赛,初始时每支球队有自己的一个分数,两队比赛,赢的一队可以获得2分,输的不扣分,平局各获得一分。
问第n只队伍有没有机会拿到第一名(不算并列)
思路:一开始没想出来,练得还不够多啊。
1:有第N只队伍的比赛时,第N只队伍必胜(+2分),此时得到第N只队伍的最大分数limit,如果初始就有队伍大于等于这个分数,那么直接不可能
2:把其他比赛和1~N-1只队伍当做结点,设置超级源点和超级汇点,超级源点到其他比赛的流量为2,其他比赛到对应的两支队伍的流量也为2
(这样对于每一场比赛,可以保证两支队伍都有可能得到0,1,2分),把所有队伍连接到超级汇点,容量是limit-1-该队容量,也就是这支队伍最多能够得到的分数。
超过这个分数就会大于等于limit了。
3:跑一遍最大流,如果满流则说明第n只队伍有机会获胜。不满流的话说明有某只队伍的分数一定会大于等于limit
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define N 5500
#define INF 1<<28
struct Edge
{
int to,next,cap;
} edge[N*100];
int cnt,head[N],d[N];
void addedge(int from,int to,int cap)
{
edge[cnt].to=to;
edge[cnt].cap=cap;
edge[cnt].next=head[from];
head[from]=cnt++;
edge[cnt].to=from;
edge[cnt].cap=0;
edge[cnt].next=head[to];
head[to]=cnt++;
}
void init()
{
cnt=0;
memset(head,-1,sizeof(head));
}
int bfs(int s,int t)
{
memset(d,-1,sizeof(d));
queue<int> q;
q.push(s);
d[s]=0;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=head[u]; i!=-1; i=edge[i].next)
{
int v=edge[i].to;
if(d[v]==-1&&edge[i].cap>0)
{
d[v]=d[u]+1;
q.push(v);
}
}
}
return d[t]!=-1;
}
int dfs(int s,int t,int f)
{
if(s==t||f==0) return f;
int flow=0;
for(int i=head[s]; i!=-1&&flow<f; i=edge[i].next)
{
int v=edge[i].to;
if(d[v]==d[s]+1&&edge[i].cap>0)
{
int x=min(f-flow,edge[i].cap);
x=dfs(v,t,x);
flow+=x;
edge[i].cap-=x;
edge[i^1].cap+=x;
if(f==0) break;
}
}
if(!flow) d[s]=-2;
return flow;
}
int Dinic(int s,int t)///起点s终点t
{
int flow=0,f;
while(bfs(s,t))
{
while(f=dfs(s,t,INF))
flow+=f;
}
return flow;
}
int main()
{
int n,m,s,t;
int a[N];
while(~scanf("%d %d",&n,&m))
{
init();
int S=0,T=n+m+2;
int sum=0;
for(int i=1; i<=n; i++)
scanf("%d",&a[i]);
for(int i=1; i<=m; i++)
{
addedge(S,i,2);
scanf("%d %d",&s,&t);
if(s==n||t==n)a[n]+=2;
else
{
addedge(i,m+s,2);
addedge(i,m+t,2);
sum+=2;
}
}
int flag=0;
for(int i=1;i<n;i++)
{
if(a[i]>=a[n]) {flag=1;break;}
else addedge(i+m,T,a[n]-1-a[i]);
}
if(flag)
printf("NO\n");
else
{
int ans=Dinic(S,T);
if(ans==sum)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}