题意
给定一张n*m的方格,每个方格放可以放4种类型的直角管道,并给出几个重要点,保证每个重要点都存在管道,且管道围成一个环。现给出每个管道连接两个方格能赚的钱,输出最多赚多少钱。若不存在方案输出impossible。
题解
可以发现每个方格都存在上下流向和左右流向的管道,且方格之间相互连接的管道方向是不同的,因此想到可以将方格黑白染色,白色代表该方格中的管道只左右流,黑色代表该方格中的管道只上下流,之后我们再把点拆成出点和入点,就可以将相邻方格连接起来了,之后我们设定流量上线为n*m,即每个方格都存在流量,对于那些非重要点,我们将其出点连向入点,代表该方格无管道,之后跑个最大费用最大流即可
代码
/**
* author: TelmaZzzz
* create: 2019-10-06-17.59.54
**/
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
void _R(int &x) {
scanf("%d", &x); }
void _R(ll &x) {
scanf("%lld", &x); }
void _R(db &x) {
scanf("%lf", &x); }
void _R(char &x) {
scanf(" %c", &x); }
void _R(char *x) {
scanf("%s", x); }
void R() {
}
template<class T, class... U> void R(T &head, U &... tail) {
_R(head); R(tail...); }
void _W(const int &x) {
printf("%d", x); }
void _W(const ll &x) {
printf("%lld", x); }
void _W(const db &x) {
printf("%.16f", x); }
void _W(const char &x) {
putchar(x); }
void _W(const char *x) {
printf("%s", x); }
template<class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()