题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2362

  裸的匹配问题,直接KM,就算是O(n^4)的KM也不会超。当然注意到题目中左边的点到右点所连的边的权值是一样的,所以完全可以贪心拍个序,然后找增广路。。。

 //STATUS:C++_AC_250MS_848KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
//typedef __int64 LL;
//typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
//const LL LNF=1LL<<60;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Node{
int val,id;
bool operator < (const Node& a)const{
return val>a.val;
}
}nod[N];
int ca; int w[N][N],y[N],vis[N];
int n,m; int dfs(int u)
{
int v;
for(v=;v<=n;v++){
if(w[u][v] && !vis[v]){
vis[v]=;
if(y[v]==- || dfs(y[v])){
y[v]=u;
return ;
}
}
}
return ;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,tot,a;
int x[N];
scanf("%d",&ca);
while(ca--)
{
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&nod[i].val);
nod[i].val*=nod[i].val;
nod[i].id=i;
}
mem(w,);
for(i=;i<=n;i++){
scanf("%d",&tot);
while(tot--){
scanf("%d",&a);
w[i][a]=nod[i].val;
}
}
sort(nod+,nod+n+); mem(x,);
mem(y,-);
for(i=;i<=n;i++){
mem(vis,);
dfs(nod[i].id);
}
for(i=;i<=n;i++)
if(y[i]!=-)x[y[i]]=i; printf("%d",x[]);
for(i=;i<=n;i++)
printf(" %d",x[i]);
putchar('\n');
}
return ;
}

ZOJ-2362 Beloved Sons 贪心 | KM的更多相关文章

  1. zoj 2362 Beloved Sons【二分匹配】

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudg ...

  2. SGU 210 Acdream 1227 Beloved Sons KM

    题目链接:点击打开链接 题意: 给定n个人 每一个人的点权 以下n行i行表示第i个人能够获得哪些数(数字从1-n.且不能反复分配) 若这个人获得了数字则你能够获得他的权值. 要你能获得的权值和最大. ...

  3. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

  4. ZOJ-2362 Beloved Sons 最大权值匹配

    题意:国王有N个儿子,现在每个儿子结婚都能够获得一定的喜悦值,王子编号为1-N,有N个女孩的编号同样为1-N,每个王子心中都有心仪的女孩,现在问如果安排,能够使得题中给定的式子和最大. 分析:其实题目 ...

  5. POJ 1862 &amp; ZOJ 1543 Stripies(贪心 | 优先队列)

    题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  6. 2017CCPC秦皇岛G ZOJ 3987Numbers(大数+贪心)

    Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB DreamGrid has a nonnegative integer n . He ...

  7. ZOJ 2702 Unrhymable Rhymes 贪心

    贪心.能凑成一组就算一组 Unrhymable Rhymes Time Limit: 10 Seconds      Memory Limit: 32768 KB      Special Judge ...

  8. ZOJ 3946 Highway Project 贪心+最短路

    题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3946 题解: 用dijkstra跑单元最短路径,如果对于顶点v,存 ...

  9. zoj 2921 Stock(贪心)

    Optiver sponsored problem. After years of hard work Optiver has developed a mathematical model that ...

随机推荐

  1. poj 1733 Parity game

    Parity game 题意:一个长度为N(N < 1e9)内的01串,之后有K(K <= 5000)组叙述,表示区间[l,r]之间1的个数为odd还是even:问在第一个叙述矛盾前说了几 ...

  2. MFC应用程序向导生成的文件

    比方说我们用Visio Studio创建了一个MFC应用程序,名称为Mysdi.在创建这个项目的时候,默认的会生成许多类和文件,就关于这些文件的内容和要点展开以下论述. 框架窗口类头文件 向导为项目M ...

  3. C语言中‘\n'为什么能表示CRLF两个字节

    为什么要说这个简单的问题? 众所周知,在Windows下文本文件的换行符是CRLF,占两个字节.在Unix下是LF,占一个字节.(还有奇葩的Mac是CR).但是C语言中直接printf一个 ‘\n’, ...

  4. 制作第一个UI图集

    按钮分有两种形式,一种是普通按钮,也就是一张没有文字的按钮图片,在需要用时,就在上面写上不同的.当前所需要的文字.量一种按钮则是图片按钮,这种按钮的特点是整个按钮就是一张图片,它既是按钮也是图片. 在 ...

  5. entity framework in mysql

    To start using Entity Framework 6 and Visual Studio 2013 is necessary to install MySQL for Visual St ...

  6. python 统计单词个数

    根据一篇英文文章统计其中单词出现最多的10个单词. # -*- coding: utf-8 -*-import urllib2import refrom collections import Coun ...

  7. Oracle常用查看表结构命令

    获取表: select table_name from user_tables; //当前用户的表 select table_name from all_tables; //所有用户的表 select ...

  8. 百度:在O(1)空间复杂度范围内对一个数组中前后连段有序数组进行归并排序

    一.题目理解 题目:数组al[0,mid-1]和al[mid,num-1]是各自有序的,对数组al[0,num-1]的两个子有序段进行merge,得到al[0,num-1]整体有序.要求空间复杂度为O ...

  9. WEB黑客工具箱之FireBug介绍

    Firefox扩展Firebug是一个全功能的Web 应用程序调试器,可以协助Web黑客洞悉复杂的Web 应用程序的内部工作机制.它有两种版本:一种可以跨浏览器使用的组件Firebug Lite,另一 ...

  10. Android ListView(Selector 颜色)

    listview_color.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...