Description
You ' re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone are here. It's a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing just as you had imagined. It could is the perfect end of a beautiful day.
But nothing ever is perfect. One of your guests works in weather forecasting. He suddenly yells, "I know that breeze! It means It going to rain heavily in just a few minutes! " Your guests all wear their best dresses and really would does like to get wet, hence they stand terrified when hearing the Bad news.
You have prepared a few umbrellas which can protect a few of your guests. The umbrellas is small, and since your guests is all slightly snobbish, no guest would share an umbrella with other guest S. The umbrellas is spread across your (gigantic) garden and just like your guests. To complicate matters even more, some of your guests can ' t run as fast as the others.
Can your guests so as many as possible find a umbrella before it starts to pour?
Given the positions and speeds of all your guests, the positions of the umbrellas, and the time until it starts to rain, F IND out what many of your guests can at the most reach an umbrella. The want to share a umbrella, however. Guests do not.
Input
The input starts with a line containing a single integer, the number of the test cases.
Each test case starts with a line containing the time t in minutes until it would start to rain (1 <=t <= 5). The next line contains the number of guests m (1 <= m <= in), followed by M lines containing X-and y-coordinates As well as the speed Si in units per minute (1 <= s I <=) of the A guest as integers, separated by spaces. After the guests, a single line contains n (1 <= n <=), the number of umbrellas, followed by n lines containing The integer coordinates of each umbrella, separated by a space.
The absolute value of all coordinates was less than 10000.
Output
For each test case, write a line containing "Scenario #i:", where I am the number of the the test case starting at 1. Then, write a single line that contains the number of guests that can at the very reach an umbrella before it starts to rain. Terminate every test case with a blank line.
Sample Input
2
1
2
1 0 3
3 0 3
2
4 0
6 0
1
2
1 1 2
3 3 2
2
2 2
4 4
Sample Output
Scenario #1:
2
Scenario #2:
2
This algorithm is more efficient relative to Hungary, because this algorithm updates +dfs with BFS to update many networks at the same time (similar to the dinic algorithm in the maximum flow), while the Hungarian algorithm can only update one path at a time
#include <cstdio> #include <algorithm> #include <cmath> #include <queue> #include <vector
> #include <cstring> using namespace std;
const int maxn=3005;
int dx[maxn],dy[maxn];//Save distance (similar to hierarchy chart) int mx[maxn],my[maxn];//save match value vector<int> G[MAXN];
int N,M,SPEED[MAXN];;
struct node {int x, y;} UM[MAXN],GUEST[MAXN]; Double Dist (node A,node b) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y))} bool BFs () {memset (dx,0,size
of DX);
memset (dy,0,sizeof dy);
Queue<int> Q;
for (int i=1; i<=n; i++) if (mx[i]==-1) Q.push (i);//will not match the X set in the join queue bool Flag=false;
while (!q.empty ()) {int U=q.front ();
Q.pop ();
for (int i=0; i<g[u].size (); i++) {int v=g[u][i];
if (!dy[v])//y[i] is represented by zero for the accessed {dy[v]=dx[u]+1;
if (my[v]!=-1)//If there is a matching value, the original value is added to the queue to re-match {dx[my[v]]=dy[v]+1; Q.push (My[v]);
} else flag=true;
}}} return flag;
} bool Dfs (int u)//Search for augmented path {for (int i=0; i<g[u].size (); i++) {int v=g[u][i];
if (dy[v]==dx[u]+1)//nonzero indicates that it has not been accessed, only if it is immediately following the next layer, access {dy[v]=0; if (my[v]==-1| |
DFS (MY[V])//satisfies match condition {my[v]=u;
Mx[u]=v;
return true;
}}} return false;
} int Hopcroft_karp () {memset (mx,-1,sizeof mx);
memset (my,-1,sizeof my);
int ans=0;
while (BFS ())//continuously BFS update residual network {for (int i=1; i<=n; i++) if (Mx[i]==-1&&dfs (i)) ans++;
} return ans;
} int main () {int case;
scanf ("%d", &case);
for (int ase=1; ase<=case; ase++) {int time;
scanf ("%d%d", &time,&n); for (int i=1; i<=n; i++) scanf ("%d%d%d", &guest[i].x,&guest[i].y,&speed[i]);
scanf ("%d", &m);
for (int i=1; i<=m; i++) scanf ("%d%d", &um[i].x,&um[i].y);
for (int i=1; i<=n; i++) g[i].clear (); for (int i=1, i<=n; i++) for (int j=1; j<=m; J + +) if (Dist (guest[i],um[j]) <= (double) time
*speed[i])//Add Edge Condition G[i].push_back (j);
printf ("Scenario #%d:\n%d\n\n", Ase,hopcroft_karp ());
} return 0;
}