#include #include #include #include using namespace std; typedef pair Paint; int main(){ int n,k,x;cin>>n>>k>>x; vector z; for(int i = 0; k > i; i++){ if(i+1==x){ char a,b;cin>>a>>b; z.push_back({0,0}); continue; } int a,b;cin>>a>>b; z.push_back({a,b}); } vector mae; for(int i = 0; n > i; i++){ mae.push_back(i+1); } vector usi(n); for(int i = 0; n > i; i++){ cin>>usi[i]; } for(int i = 0; k > i; i++){ if(!z[i].first)break; swap(mae[z[i].first-1],mae[z[i].second-1]); } for(int i = k-1; 0 <= i; i--){ if(!z[i].first)break; swap(usi[z[i].first-1],usi[z[i].second-1]); } vector ans; for(int i = 0; n > i; i++){ if(mae[i]!=usi[i]){ ans.push_back(i+1); } } cout << ans[0] << " " << ans[1] << endl; }