Niloy007

Task - 2

Apr 30th, 2021
685
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Part 1
  2.  
  3.  
  4. #include <bits/stdc++.h>
  5. #define Niloy
  6. #define int int64_t
  7. #define mx (int) 1e5 + 123
  8. #define MOD 1e9
  9. #define pb push_back
  10. #define pairs pair<int, int>
  11. #define vi vector<int>
  12. #define vb vector<bool>
  13. #define vii vector<pairs>
  14. #define lb lower_bound
  15. #define ub upper_bound
  16. #define endl '\n'
  17. #define llu unsigned long long
  18. using namespace std;
  19. /* ----------------------------------------------------------------------------------- */
  20.  
  21. // Input/Output
  22. #define fastInput ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  23. #define all(x) x.begin(), x.end()
  24. #define square(a) (a * a)
  25. #define mem(a, b) memset(a, b, sizeof(a))
  26.  
  27. // Fractional Number
  28. #define fraction()        cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed, ios::floatfield);
  29.  
  30. #define scan(a)           scanf("%lld", &a);
  31. #define scan2(a, b)       scanf("%lld %lld", &a, &b);
  32. #define scan3(a, b, c)    scanf("%lld %lld %lld", &a, &b, &c);
  33. #define scan4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  34.  
  35. #define scanD(a)          scanf("%lf", &a);
  36. #define scanD2(a, b)      scanf("%lf %lf", &a, &b);
  37. #define scanD3(a, b, c)   scanf("%lf %lf %lf", &a, &b, &c);
  38. #define scanD4(a, b, c, d)scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
  39.  
  40.  
  41. #define print(a)           printf("%lld\n", a);
  42. #define print2(a, b)       printf("%lld %lld\n", a, b);
  43. #define print3(a, b, c)    printf("%lld %lld %lld\n", a, b, c);
  44. #define print4(a, b, c, d) printf("%lld %lld %lld %lld\n", a, b, c, d);
  45.  
  46. #define printD(a)          printf("%lf\n", a);
  47. #define printD2(a, b)      printf("%lf %lf\n", a, b);
  48. #define printD3(a, b, c)   printf("%lf %lf %lf\n", a, b, c);
  49. #define printD4(a, b, c, d)printf("%lf %lf %lf %lf\n", a, b, c, d);
  50. #define printTwoD(a)       printf("%.2lf\n", a);
  51.  
  52. // File I/O
  53. #define read(x)  freopen(x, "r", stdin);
  54. #define write(x) freopen(x, "w", stdout);
  55.  
  56. // Loops
  57. #define rep(i, a, n) for (int i = a; i < n; i++)
  58. #define REP(i, a, n) for (int i = a; i <= n; i++)
  59. #define rev(i, n, a) for (int i = n - 1; i >= a; i--)
  60. #define REV(i, n, a) for (int i = n; i >= a; i--)
  61. #define inputArray(a,n) rep(i, 0, n) cin >> a[i];
  62. #define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
  63. #define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;
  64.  
  65. /* ----------------------------------------------------------------------------------- */
  66.  
  67. #define Cases  cout << "Case " << ++Case << ": ";
  68. #define __test int tt; int Case=0; cin >> tt; while(tt--)
  69. #define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  70.  
  71. #define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, m){cout<<A[i][j]<<"";}cout<<"\n";}cout<<"\n";}
  72. #define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
  73. #define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}
  74.  
  75. /* ----------------------------------------------------------------------------------- */
  76.  
  77. int gcd(int n, int m) { return m ? gcd(m, n % m) : n; }
  78. int lcm(int n, int m) { return n / gcd(n, m) * m; }
  79.  
  80. struct debugger {
  81.     typedef string::iterator si;
  82.     static void call(si it, si ed) {}
  83.     template<typename T, typename ... aT>
  84.     static void call(si it, si ed, T a, aT... rest) {
  85.         string b;
  86.         for(; *it!=','; ++it)
  87.             if(*it!=' ')
  88.                 b+=*it;
  89.         cout << b << "=" << a << " ";
  90.         call(++it, ed, rest...);
  91.     }
  92. };
  93.  
  94. /* ----------------------------------------------------------------------------------- */
  95. void input() {
  96. #ifdef Niloy
  97.     read("input.txt");  
  98.     write("output.txt");
  99. #endif
  100. }
  101.  
  102. /* ----------------------------------------------------------------------------------- */
  103.  
  104. vi adj[mx];
  105.  
  106. void solve() {
  107.     int n, m;
  108.     scan2(n, m);
  109.  
  110.     REP(i, 1, m) {
  111.         int u, v;
  112.         scan2(u, v);
  113.         adj[u].pb(v);
  114.         adj[v].pb(u);
  115.     }
  116.  
  117.     REP(i, 1, n) {
  118.         // cout << "Adjacent list of " << i << ": ";
  119.         for (auto j : adj[i]) {
  120.             cout << j << " ";
  121.         }
  122.         cout << endl;
  123.     }
  124. }
  125.  
  126. int32_t main() {
  127.     // input();
  128.     // fastInput;
  129.     solve();
  130.  
  131.     // __test {
  132.     //  solve();
  133.     // }
  134.  
  135.     // showTime;
  136.     return 0;
  137. }
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. //Part 2
  146.  
  147.  
  148. #include <bits/stdc++.h>
  149. #define Niloy
  150. #define int int64_t
  151. #define mx (int) 1e5 + 123
  152. #define MOD 1e9
  153. #define pb push_back
  154. #define pairs pair<int, int>
  155. #define vi vector<int>
  156. #define vb vector<bool>
  157. #define vii vector<pairs>
  158. #define lb lower_bound
  159. #define ub upper_bound
  160. #define endl '\n'
  161. #define llu unsigned long long
  162. using namespace std;
  163. /* ----------------------------------------------------------------------------------- */
  164.  
  165. // Input/Output
  166. #define fastInput ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  167. #define all(x) x.begin(), x.end()
  168. #define square(a) (a * a)
  169. #define mem(a, b) memset(a, b, sizeof(a))
  170.  
  171. // Fractional Number
  172. #define fraction()        cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed, ios::floatfield);
  173.  
  174. #define scan(a)           scanf("%lld", &a);
  175. #define scan2(a, b)       scanf("%lld %lld", &a, &b);
  176. #define scan3(a, b, c)    scanf("%lld %lld %lld", &a, &b, &c);
  177. #define scan4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  178.  
  179. #define scanD(a)          scanf("%lf", &a);
  180. #define scanD2(a, b)      scanf("%lf %lf", &a, &b);
  181. #define scanD3(a, b, c)   scanf("%lf %lf %lf", &a, &b, &c);
  182. #define scanD4(a, b, c, d)scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
  183.  
  184.  
  185. #define print(a)           printf("%lld\n", a);
  186. #define print2(a, b)       printf("%lld %lld\n", a, b);
  187. #define print3(a, b, c)    printf("%lld %lld %lld\n", a, b, c);
  188. #define print4(a, b, c, d) printf("%lld %lld %lld %lld\n", a, b, c, d);
  189.  
  190. #define printD(a)          printf("%lf\n", a);
  191. #define printD2(a, b)      printf("%lf %lf\n", a, b);
  192. #define printD3(a, b, c)   printf("%lf %lf %lf\n", a, b, c);
  193. #define printD4(a, b, c, d)printf("%lf %lf %lf %lf\n", a, b, c, d);
  194. #define printTwoD(a)       printf("%.2lf\n", a);
  195.  
  196. // File I/O
  197. #define read(x)  freopen(x, "r", stdin);
  198. #define write(x) freopen(x, "w", stdout);
  199.  
  200. // Loops
  201. #define rep(i, a, n) for (int i = a; i < n; i++)
  202. #define REP(i, a, n) for (int i = a; i <= n; i++)
  203. #define rev(i, n, a) for (int i = n - 1; i >= a; i--)
  204. #define REV(i, n, a) for (int i = n; i >= a; i--)
  205. #define inputArray(a,n) rep(i, 0, n) cin >> a[i];
  206. #define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
  207. #define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;
  208.  
  209. /* ----------------------------------------------------------------------------------- */
  210.  
  211. #define Cases  cout << "Case " << ++Case << ": ";
  212. #define __test int tt; int Case=0; cin >> tt; while(tt--)
  213. #define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  214.  
  215. #define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, m){cout<<A[i][j]<<"";}cout<<"\n";}cout<<"\n";}
  216. #define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
  217. #define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}
  218.  
  219. /* ----------------------------------------------------------------------------------- */
  220.  
  221. int gcd(int n, int m) { return m ? gcd(m, n % m) : n; }
  222. int lcm(int n, int m) { return n / gcd(n, m) * m; }
  223.  
  224. struct debugger {
  225.     typedef string::iterator si;
  226.     static void call(si it, si ed) {}
  227.     template<typename T, typename ... aT>
  228.     static void call(si it, si ed, T a, aT... rest) {
  229.         string b;
  230.         for(; *it!=','; ++it)
  231.             if(*it!=' ')
  232.                 b+=*it;
  233.         cout << b << "=" << a << " ";
  234.         call(++it, ed, rest...);
  235.     }
  236. };
  237.  
  238. /* ----------------------------------------------------------------------------------- */
  239. void input() {
  240. #ifdef Niloy
  241.     read("input.txt");  
  242.     write("output.txt");
  243. #endif
  244. }
  245.  
  246. /* ----------------------------------------------------------------------------------- */
  247.  
  248. vi adj[mx];
  249.  
  250. void solve() {
  251.     int n, m;
  252.     scan2(n, m);
  253.  
  254.     REP(i, 1, m) {
  255.         int u, v;
  256.         scan2(u, v);
  257.         adj[u].pb(v);
  258.     }
  259.  
  260.     REP(i, 1, n) {
  261.         // cout << "Adjacent list of " << i << ": ";
  262.         for (auto j : adj[i]) {
  263.             cout << j << " ";
  264.         }
  265.         cout << endl;
  266.     }
  267. }
  268.  
  269. int32_t main() {
  270.     // input();
  271.     // fastInput;
  272.     solve();
  273.  
  274.     // __test {
  275.     //  solve();
  276.     // }
  277.  
  278.     // showTime;
  279.     return 0;
  280. }
  281.  
  282.  
  283.  
  284.  
RAW Paste Data