Advertisement
GerONSo

Untitled

Feb 11th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<vector>
  7. #include<set>
  8. #include<map>
  9. #include<bits/stdc++.h>
  10.  
  11. #define ll long long
  12. #define all(x) begin(x),end(x)
  13. #define pb(x) push_back(x)
  14. #define INPUT "input.txt"
  15. #define OUTPUT "output.txt"
  16.  
  17.  
  18. using namespace std;
  19.  
  20. typedef vector<int> vi;
  21. typedef pair<int,int> pii;
  22.  
  23. vi a(22);
  24. vi b(22);
  25. int n,m;
  26.  
  27. void remake(){
  28. for(int i=1;i<=n;i++){
  29. for(int j=1;j<=n;j++){
  30. if(i==a[j])
  31. b[i]=j;
  32. }
  33. }
  34. }
  35.  
  36. int main() {
  37. ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  38.  
  39. cin>>n>>m;
  40. a.resize(n+1);
  41. b.resize(n+1);
  42. for(int i=1;i<=n;i++)
  43. a[i]=i;
  44. for(int i=0;i<m;i++){
  45. int x,y;
  46. cin>>x>>y;
  47. swap(a[x],a[y]);
  48. }
  49. for(int i=1;i<=n;i++){
  50. for(int j=1;j<=n;j++){
  51. if(i==a[j])
  52. b[i]=j;
  53. }
  54. }
  55. for(int i:b)
  56. cout<<i<<" ";
  57. cout<<endl;
  58. for(int i=1;i<n;i++){
  59. if(a[i]!=i){
  60. if(b[i]!=n-1)
  61. cout<<b[i]<<" "<<n-1<<endl;
  62. swap(a[b[i]],a[n-1]);
  63.  
  64. remake();
  65. if(n-1!=a[n-1])
  66. cout<<n-1<<" "<<a[n-1]<<endl;
  67. swap(a[n-1],a[a[n-1]]);
  68. remake();
  69. }
  70.  
  71. }
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement