# UVA - 563 Crimewave【最大流】

Nieuw Knollendam is a very modern town. This becomes clear already when looking at the layout of its map, which is just a rectangular grid of streets and avenues. Being an important trade centre, Nieuw Knollendam also has a lot of banks. Almost on every crossing a bank is found (although there are never two banks at the same crossing). Unfortunately this has attracted a lot of criminals. Bank hold-ups are quite common, and often on one day several banks are robbed. This has grown into a problem, not only to the banks, but to the criminals as well. After robbing a bank the robber tries to leave the town as soon as possible, most of the times chased at high speed by the police. Sometimes two running criminals pass the same crossing, causing several risks: collisions, crowds of police at one place and a larger risk to be caught.

To prevent these unpleasant situations the robbers agreed to consult together. Every Saturday night they meet and make a schedule for the week to come: who is going to rob which bank on which day? For every day they try to plan the get-away routes, such that no two routes use the same crossing. Sometimes they do not succeed in planning the routes according to this condition, although they believe that such a planning should exist.

Given a grid of  and the crossings where the banks to be robbed are located, find out whether or not it is possible to plan a get-away route from every robbed bank to the city-bounds, without using a crossing more than once.

## Input

The first line of the input contains the number of problems p to be solved.
• The first line of every problem contains the number s of streets ( ), followed by the numbera of avenues ( ), followed by the number b () of banks to be robbed.
• Then b lines follow, each containing the location of a bank in the form of two numbers x (the number of the street) and y (the number of the avenue). Evidently  and .

## Output

The output file consists of p lines. Each line contains the text possible or not possible. If it is possible to plan non-crossing get-away routes, this line should contain the word: possible. If this is not possible, the line should contain the words not possible.

## Sample Input

2
6 6 10
4 1
3 2
4 2
5 2
3 4
4 4
5 4
3 6
4 6
5 6
5 5 5
3 2
2 3
3 3
4 3
3 4


## Sample Output

possible
not possible


/*************
uva 563
2016-08-30 10:54:18
0	0
C++ 5.3.0
2725
************/
#include <stdio.h>
#include<cstring>
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int oo=0x3f3f3f3f;
const int mm=900000;
const int mn=900000;
int node ,scr,dest,edge;
int ver[mm],flow[mm],Next[mm];
void prepare(int _node,int _scr,int _dest)
{
node=_node,scr=_scr,dest=_dest;
for(int i=0; i<node; ++i)
edge=0;
}
{
}
bool Dinic_bfs()
{
int i,u,v,l,r=0;
for(i=0; i<node; i++)
dis[i]=-1;
dis[q[r++]=scr]=0;
for(l=0; l<r; ++l)
{
{
if(flow[i]&&dis[v=ver[i]]<0)
{
dis[q[r++]=v]=dis[u]+1;
if(v==dest)
return 1;
}
}
}
return 0;
}
int Dinic_dfs(int u,int exp)
{
if(u==dest)
return exp;
for(int &i=work[u],v,tmp; i>=0; i=Next[i])
if(flow[i]&&dis[v=ver[i]]==dis[u]+1&&(tmp=Dinic_dfs(v,min(exp,flow[i])))>0)
{
flow[i]-=tmp;
flow[i^1]+=tmp;
return tmp;
}
return 0;
}
int Dinic_flow()
{
int i,ret=0,delta;
while(Dinic_bfs())
{
for(i=0; i<node; i++)
while(delta=Dinic_dfs(scr,oo))
ret+=delta;
}
return ret;
}
int n,m,t,Q;
int main()
{
//  freopen("cin.txt","r",stdin);
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&Q);
prepare(n*m*2+2,0,n*m*2+1);
for(int i=1;i<=Q;i++)
{
int a,b;
scanf("%d%d",&a,&b);
}
//
//
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
//(i,j)=>(i-1,j)  (i+1,j)  (i,j+1)  (i,j-1)
}
}
//printf("%d\n",);
if(Q==Dinic_flow())puts("possible");
else puts("not possible");
}
return 0;
}


#### uva 563 Crimewave（最大流）

2015-07-18 19:54:02

#### UVA 563 - Crimewave(最大流)

2013-12-03 19:44:06

#### UVa 563 - Crimewave 最大流

2014-05-31 11:29:17

#### UVa 563 Crimewave / 最大流EK

2013-12-18 18:36:21

#### UVA 563 Crimewave (最大流，拆点)

2014-09-04 22:12:28

#### Crimewave (Uva 563 最大流拆点）

2015-08-01 09:28:42

#### uva 563 - Crimewave(分点+最大流)

2012-04-18 14:13:17

#### uva 563 - Crimewave（网络流最大流）

2013-11-22 14:48:13

#### UVA 563 - Crimewave

2011-03-28 15:34:00

#### UVA, 563 Crimewave

2016-05-06 16:12:00