#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int nMax= 1000;
class edge{
public:
int v,nex;
};edge e[nMax];
int n,k,head[nMax]; // head[i]是以点i为起点的链表头部
void addedge( int a, int b){ // 向图中加有向边的算法,注意加上的是有向边 // b为a的后续节点既是a---->b
e[k].v=b;
e[k].nex=head[a];
head[a]=k;
k++;
}
int main(){
int i,a,b,w,k= 1;
scanf( " %d ",&n);
memset(head, 0, sizeof(head));
for(i= 0;i<n;i++){
scanf( " %d%d ",&a,&b);
addedge(a,b); // 添加一条由a指向b的边
}
cin>>w; // 输出w点所指向的点
for(i=head[w];i;i=e[i].nex){
cout<<e[i].v<<endl;
}
cout<< " end\n ";
return 0;
}
#include<cstring>
#include<cstdio>
using namespace std;
const int nMax= 1000;
class edge{
public:
int v,nex;
};edge e[nMax];
int n,k,head[nMax]; // head[i]是以点i为起点的链表头部
void addedge( int a, int b){ // 向图中加有向边的算法,注意加上的是有向边 // b为a的后续节点既是a---->b
e[k].v=b;
e[k].nex=head[a];
head[a]=k;
k++;
}
int main(){
int i,a,b,w,k= 1;
scanf( " %d ",&n);
memset(head, 0, sizeof(head));
for(i= 0;i<n;i++){
scanf( " %d%d ",&a,&b);
addedge(a,b); // 添加一条由a指向b的边
}
cin>>w; // 输出w点所指向的点
for(i=head[w];i;i=e[i].nex){
cout<<e[i].v<<endl;
}
cout<< " end\n ";
return 0;
}