求年份和城市的匹配
1 5 6 2 2 1 2 2 1 3 1 1 1 2 3 1 1 2 1 2
3 0 2 1HintNo city was rebuilt in the third year,city 1 and city 3 were rebuilt in the fourth year,and city 2 was rebuilt in the sixth year.
/* *********************************************** Author :CKboss Created Time :2015年08月05日 星期三 16时16分29秒 File Name :HDOJ5352.cpp ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> using namespace std; const int maxn=10010; int n,m,k; int mark[maxn]; bool g[202][202],used[maxn]; /*************edge*****************/ struct Edge { int to,next; }edge[maxn]; int Adj[maxn],Size; void init() { memset(Adj,-1,sizeof(Adj)); Size=0; } void Add_Edge(int u,int v) { edge[Size].to=v; edge[Size].next=Adj[u]; Adj[u]=Size++; } void link_edge(int year,int u) { Add_Edge(year,u); for(int i=1;i<=n;i++) { if(g[u][i]==true&&used[i]==false) { used[i]=true; link_edge(year,i); } } } /*************hungary*****************/ int linker[maxn]; bool dfs(int u) { for(int i=Adj[u];~i;i=edge[i].next) { int v=edge[i].to; if(!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) { linker[v]=u; return true; } } } return false; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int T_T; scanf("%d",&T_T); while(T_T--) { scanf("%d%d%d",&n,&m,&k); init(); memset(g,0,sizeof(g)); memset(mark,0,sizeof(mark)); for(int i=0,k,x,y;i<m;i++) { scanf("%d",&k); if(k==1) { scanf("%d",&x); memset(used,false,sizeof(used)); used[x]=true; link_edge(i,x); mark[i]=true; } else if(k==2) { scanf("%d%d",&x,&y); g[x][y]=g[y][x]=1; } else if(k==3) { int p; scanf("%d",&p); while(p--) { scanf("%d%d",&x,&y); g[x][y]=g[y][x]=0; } } } int au=0; vector<int> vi; memset(linker,-1,sizeof(linker)); for(int i=m-1;i>=0;i--) { if(mark[i]==true) { int tu=0; for(int j=0;j<k;j++) { memset(used,0,sizeof(used)); if(dfs(i)==true) tu++; } au+=tu; vi.push_back(tu); } } printf("%d\n",au); for(int sz=vi.size(),i=sz-1;i>=0;i--) printf("%d%c",vi[i],(i==0)?'\n':' '); } return 0; }