Description
After this year's college-entrance exam, the teacher did a survey in his class on students' score. There are n students in the class. The students didn't want to tell their teacher their exact score; they only told their teacher their rank in the province (in the form of intervals).
After asking all the students, the teacher found that some students didn't tell the truth. For example, Student1 said he was between 5004-th and 5005-th, Student2 said he was between 5005-th and 5006-th, Student3 said he was between 5004-th and 5006-th, Student4 said he was between 5004-th and 5006-th, too. This situation is obviously impossible. So at least one told a lie. Because the teacher thinks most of his students are honest, he wants to know how many students told the truth at most.
Input
There is an integer in the first line, represents the number of cases (at most 100 cases). In the first line of every case, an integer n(n60)represents the number of students. In the next n lines of every case, there are 2 numbers in each line, Xi and Yi(1XiYi100000), means the i-th student's rank is between Xi and Yi, inclusive.
Output
Output 2 lines for every case. Output a single number in the first line, which means the number of students who told the truth at most. In the second line, output the students who tell the truth, separated by a space. Please note that there are no spaces at the head or tail of each line. If there are more than one way, output the list with maximum lexicographic. (In the example above, 1 2 3;1 2 4;1 3 4;2 3 4 are all OK, and 2 3 4 with maximum lexicographic)
Sample Input
2 4 5004 5005 5005 5006 5004 5006 5004 5006 7 4 5 2 3 1 2 2 2 4 4 2 3 3 4
Sample Output
3 2 3 4 5 1 3 5 6 7
#include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <string> #include <iostream> #include <sstream> #include <map> #include <set> #include <queue> #include <stack> #include <fstream> #include <numeric> #include <iomanip> #include <bitset> #include <list> #include <stdexcept> #include <functional> #include <utility> #include <ctime> using namespace std; #define PB push_back #define MP make_pair #define CLR(vis) memset(vis,0,sizeof(vis)) #define MST(vis,pos) memset(vis,pos,sizeof(vis)) #define MAX3(a,b,c) max(a,max(b,c)) #define MAX4(a,b,c,d) max(max(a,b),max(c,d)) #define MIN3(a,b,c) min(a,min(b,c)) #define MIN4(a,b,c,d) min(min(a,b),min(c,d)) #define PI acos(-1.0) #define INF 0x7FFFFFFF #define LINF 1000000000000000000LL #define eps 1e-8 typedef long long ll; typedef unsigned long long ull; struct node{ int x,y; }e[66]; int n; int link[100010]; int use[100010]; bool dfs(int k) { int i,j; for(i=e[k].x;i<=e[k].y;i++) { if (use[i]==0) { use[i]=1; j=link[i]; link[i]=k; if (j==-1||dfs(j)) { return true; } link[i]=j; } } return false; } int hungary() { int num=0; int i; for(i=n;i>=1;i--) { CLR(use); if(dfs(i)) num++; } return num; } int main() { int t; cin>>t; while(t--) { scanf("%d",&n); MST(link,-1); for(int i=1;i<=n;i++) { scanf("%d%d",&e[i].x,&e[i].y); } int ans=0; ans=hungary(); printf("%d\n",ans); int a[66]; int g=0; for(int i=1;i<=n;i++) { for(int j=e[i].x;j<=e[i].y;j++) { if(link[j]>0) { a[g++]=link[j]; link[j]=-1; } } } sort(a,a+g); for(int i=0;i<g;i++) { if(i>0) printf(" "); printf("%d",a[i]); } printf("\n"); } return 0; }