标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1542 Accepted Submission(s): 769
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<algorithm> using namespace std; int tt,n,mark[100010],link[100010],vis[100010]; struct node { int x,y; }e[100010]; bool dfs(int t) { for(int i=e[t].x;i<=e[t].y;i++) { if(mark[i]==-1) { mark[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=t; vis[t]=1; return true; } } } return false; } int main() { scanf("%d",&tt); while(tt--) { memset(vis,0,sizeof(vis)); int sum=0; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&e[i].x,&e[i].y); memset(link,-1,sizeof(link)); for(int i=n;i>=1;i--) { memset(mark,-1,sizeof(mark)); if(dfs(i)) sum++; } printf("%d\n",sum); for(int i=1;i<=n;i++) { if(vis[i]) { if(sum>1) printf("%d ",i); else printf("%d\n",i); sum--; } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4247889.html