Changchun University fourteenth Programming Contest (reproduce season) L

L.Homework Stream

Topic links: https://ac.nowcoder.com/acm/contest/912/L

topic


As a top student Ban Heng large, small r every day a lot of homework to be completed, such as engineering drawing, engineering drawing and engineering drawing.

It is clear that homework is to have order. Dependencies between jobs, one job is not done, we can not begin to do another job. For example, the C language compilation of the job depends on the job, because of the small r can decompile the assembler compile the results he wanted with the C language.

Jobs are now known there are n (number 1 ~ n) of m and dependencies between jobs, r wondered small number k which is dependent on the job the job, and a job which is dependent on the number k jobs.
Description Input:

Input three positive integers first row n-, m, K (1 ≦ n, m, k≤106)

, have the meaning described in the subject.

Next m lines of two positive integers xi, yi (1≤xi, yi≤106) , representative of operation dependent on xi Yi

.

Duplicate to ensure the input dependency does not exist, there is no circular dependencies.

Description Output:

Output total of two lines.

The first line of output job number k-dependent job number, each number separated by a space.

The second line of output is dependent on the number k of the job number, each number is also separated by spaces.

Job number sequentially each line of output arbitrary.

Example 1
input
. 5. 4. 3
. 3 1
. 3 2
. 4. 3
. 5. 3

outputs
1 2
. 4. 5

Example 2
inputs
. 3 2 1
2 1
. 3 2

Output
2

Description

If you do not rely or depend on the job, but also output a blank line (that is, the output must be a total of two line breaks)

Note:

dependency does not meet the transitive, that you need to consider indirect dependencies.

Thinking

Water problem, the line judge into an array

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
 
    int n,m,k;
    vector<int>sh,ch;
    while(cin>>n>>m>>k)
    {
        int a,b;
     for(int i=0;i<m;i++)
     {
         cin>>a>>b;
         if(a==k)
             sh.push_back(b);
         else if(b==k)
             ch.push_back(a);
     }
     if(!sh.size())
         cout<<endl;
     if(sh.size())
     {
         copy(sh.begin(),sh.end(),ostream_iterator<int>(cout," "));
         cout<<endl;
     }
    if(!ch.size())
        cout<<endl;
    if(ch.size())
    {
        copy(ch.begin(),ch.end(),ostream_iterator<int>(cout," "));
        cout<<endl;
    }
    sh.clear();
    ch.clear();
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Vampire6/p/10992451.html