Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. #define pb push_back
  4. #define mp make_pair
  5. #define fst first
  6. #define snd second
  7. #define fr(i,n) for(int i=0;i<n;i++)
  8. #define frr(i,n) for(int i=1;i<=n;i++)
  9. #define ms(x,i) memset(x,i,sizeof(x))
  10. #define dbg(x) cout << #x << " = " << x << endl
  11. #define all(x) x.begin(),x.end()
  12. #define gnl cout << endl
  13. #define olar cout << "olar" << endl
  14. #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
  15. typedef long long int ll;
  16. typedef pair<int,int> pii;
  17. typedef vector<int> vi;
  18. typedef vector<pii> vii;
  19. typedef pair<ll,ll> pll;
  20. const int INF = 0x3f3f3f3f;
  21. const ll llINF = 0x3f3f3f3f3f3f3f;
  22. const int MAXN = 100100;
  23. const ll mod = 1000000007;
  24. typedef vector< vector<ll> > matrix;
  25.  
  26. matrix nodes;
  27. ll n,m,k;
  28.  
  29. matrix operator*(matrix a, matrix b){
  30.  
  31. int a1=a.size(),a2=a[0].size();
  32. int b1=b.size(),b2=b[0].size();
  33.  
  34. matrix aux;
  35. aux.resize(a1);
  36. fr(i,a1)
  37. aux[i].resize(b2);
  38.  
  39. fr(i,a1){
  40. fr(j,b2){
  41. aux[i][j]=0ll;
  42. fr(k,a2){
  43. aux[i][j]+=a[i][k]*b[k][j];
  44. aux[i][j]=aux[i][j]%mod;
  45. }
  46. }
  47. }
  48.  
  49. return aux;
  50.  
  51. }
  52.  
  53. matrix gen_id(){
  54. matrix aux;
  55. aux.resize(n);
  56. fr(i,n){
  57. aux[i].resize(n);
  58. aux[i][i]=1ll;
  59. }
  60. return aux;
  61. }
  62.  
  63. matrix fastxp(matrix a, ll b){
  64.  
  65. matrix ans = gen_id();
  66.  
  67. while(b>0){
  68. if(b%2)
  69. ans=a*ans;
  70. a=a*a;
  71. b=b/2;
  72. }
  73.  
  74. return ans;
  75.  
  76. }
  77.  
  78. void print_matrix(matrix a){
  79.  
  80. int x=a.size(),y=a[0].size();
  81. fr(i,x){
  82. fr(j,y){
  83. cout << a[i][j] << " ";
  84. }
  85. gnl;
  86. }
  87.  
  88. }
  89.  
  90. int main(){
  91.  
  92. cin >> n >> m >> k;
  93.  
  94. nodes.resize(n);
  95.  
  96. fr(i,n)
  97. nodes[i].resize(n);
  98.  
  99. fr(i,m){
  100. int a,b; cin >> a >> b;
  101. a--;b--;
  102. nodes[a][b]++;
  103. nodes[b][a]++;
  104. }
  105.  
  106. matrix t = fastxp(nodes,k);
  107. //print_matrix(t);
  108.  
  109. fr(i,n){
  110. for(int j=i+1;j<n;j++){
  111. if(t[i][j])
  112. cout << t[i][j];
  113. else
  114. cout << -1;
  115. cout << " ";
  116. }
  117. gnl;
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement