Advertisement
Shahd_Elmeniawy

From adjacency matrix to adjacency list

Mar 6th, 2023
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3.  
  4. using namespace std;
  5. using namespace __gnu_cxx;
  6. using namespace __gnu_pbds;
  7.  
  8. #define ll long long
  9. #define endl  "\n"
  10. #define int ll
  11. #define PI  3.14159265359
  12. #define OO  2000000000
  13. #define M0D 1000000007
  14. #define sz(m)       (ll)(m.size())
  15. #define all(SHA)    SHA.begin(),SHA.end()
  16. #define rall(SHA)   SHA.rbegin(),SHA.rend()
  17. #define TIME        cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  18. #define tc          ll testcase;   cin>>testcase;   while(testcase--)
  19. #define cin2(m)     for(auto& it : m){for(auto& jt : it ){ cin>>jt; } }
  20. #define cout2(m)    for(auto& it : m){for(auto& jt : it ){ cout<<jt << " "; } cout<<endl; }
  21. #define cin(m)     for(auto& it : m)cout<<it
  22. #define cout(m)     for(auto& it : m)cout<<it
  23. #define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
  24. #define multi_ordered_set      tree<ll, null_type, greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
  25.  
  26.  
  27. template<typename T>
  28. istream &operator>>(istream &in, vector<T> &v) {
  29.     for (T &i: v) in >> i;
  30.     return in;
  31. }
  32.  
  33. template<typename T>
  34. ostream &operator<<(ostream &out, const vector<T> &v) {
  35.     for (const T &x: v)
  36.         out << x << ' ';
  37.     return out;
  38. }
  39.  
  40. //ordered_set s
  41. //s.order_of_key( Thekey )
  42. //s.find_by_order( indx )
  43. //__builtin_popcount(x) num of ones
  44.  
  45.  
  46.  
  47. /* B0Ma
  48.                     " وَأَن لَّيْسَ لِلْإِنسَانِ إِلَّا مَا سَعَى ﴿39﴾ وَأَنَّ سَعْيَهُ سَوْفَ يُرَى ﴿40﴾ ثُمَّ يُجْزَاهُ الْجَزَاء الْأَوْفَى "
  49.                                       لو كان سهلاً لفعله الجميع....
  50.                                       Don't tell people your plans, show them your results.
  51. */
  52.  
  53. void B0Ma() {
  54.     ios_base::sync_with_stdio(false);
  55.     cin.tie(nullptr);
  56.     cout.tie(nullptr);
  57.  
  58.  
  59. #ifndef ONLINE_JUDGE
  60.     freopen("in.txt", "r", stdin);
  61.     freopen("out.txt", "w", stdout);
  62. #endif
  63. }
  64.  
  65. int32_t main() {
  66.     B0Ma();
  67.     int n;
  68.     cin >> n;
  69.     vector<vector<int>> v(n, vector<int>(n));
  70.     cin2(v);
  71.     for (int i = 0; i < n; i++) {
  72.         vector<int> sol;
  73.         for (int j = 0; j < n; j++) {
  74.             if (v[i][j] == 1)sol.push_back(j + 1);
  75.         }
  76.         cout << sz(sol) << " ";
  77.         cout << sol << endl;
  78.     }
  79.  
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement