HDOJ question 3729 I & amp; #39; m Telling the Truth (Bipartite Graph)

Source: Internet
Author: User

HDOJ question 3729 I & #39; m Telling the Truth (Bipartite Graph)
I'm Telling the TruthTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1629 Accepted Submission (s): 805



Problem 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, when said he was between 5004th and 5005th, then said he was between 5005th and 5006th, then said he was between 5004th and 5006th, then said he was between 5004th and second, too. this situation is obviusly 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 (n <= 60) represents the number of students. in the next n lines of every case, there are 2 numbers in each line, Xi and Yi (1 <= Xi <= Yi <= 100000 ), means the I-th student's rank is between Xi and Yi, inclusive.


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

245004 50055005 50065004 50065004 500674 52 31 22 24 42 33 4

Sample Output
32 3 451 3 5 6 7

Source 2010 Asia Tianjin Regional Contest
Recommend zhouzeyong | We have carefully selected several similar problems for you: 3724 3722 3723 3725 question: everyone speaks their ranking range and asks the maximum number of people to tell the truth, and output the numbers of people who tell the truth. If there are many situations that meet the requirements, output the largest sequence of ac code.
#include
 
  #include
  
   #include
   
    int head[100100],vis[100100],cnt,ans[100100],link[100100];int cmp(const void *a,const void *b){return *(int *)a-*(int *)b;}struct s{int u,v,next;}edge[100010];void add(int u,int v){edge[cnt].u=u;edge[cnt].v=v;edge[cnt].next=head[u];head[u]=cnt++;}int dfs(int u){int i;for(i=head[u];i!=-1;i=edge[i].next){int v=edge[i].v;if(!vis[v]){vis[v]=1;if(link[v]==-1||dfs(link[v])){link[v]=u;return 1;}}}return 0;}int main(){int t;scanf(%d,&t);while(t--){int n;scanf(%d,&n);int i,j;cnt=0;memset(head,-1,sizeof(head));memset(link,-1,sizeof(link));for(i=1;i<=n;i++){int a,b;scanf(%d%d,&a,&b);for(j=a;j<=b;j++)add(i,j);}int top=0;for(i=n;i>0;i--){memset(vis,0,sizeof(vis));if(dfs(i)){ans[top++]=i;}}printf(%d,top);qsort(ans,top,sizeof(ans[0]),cmp);for(i=0;i
    
     

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.