#include #include #include #include using namespace std; #define FOR(x,y) for(int x = 0;x < y;x++) template class UF { public: vector par,rank,cnt; UF() {par=rank=vector(um,0); cnt=vector(um,1); for(int i=0;irank[y]) return par[x]=y; rank[x]+=rank[x]==rank[y]; return par[y]=x; } }; int main(int argc, const char * argv[]) { int N, K; cin >> N >> K; vector data(N); FOR(i,N){ data[i] = i; } FOR(i,K){ int x, y; cin >> x >> y; swap(data[x-1], data[y-1]); } vector A(N); FOR(i,N)cin >> A[i], --A[i]; vector> swaps; FOR(t,N){ for(int i=0;i+1 A[data[i+1]]){ swaps.emplace_back(i, i+1); swap(data[i], data[i+1]); } } } cout << swaps.size() << endl; for(auto swp : swaps){ cout << swp.first + 1 << " " << swp.second + 1 << endl; } return 0; }