Advertisement
Iamtui1010

lamquen.cpp

Dec 2nd, 2022 (edited)
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<set>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. void show(long n, const vector<long> &a)
  11. {
  12.     for (long i = 1; i <= n; ++i)
  13.         cout << a[i] << ' ';
  14.     cout << nln;
  15. }
  16.  
  17. void rc(long ps, const vector<set<long>> &mat, vector<long> &flg, long cnt, long &qlt)
  18. {
  19.     flg[ps] = cnt;
  20.     for (auto nps : mat[ps])
  21.         if (!flg[nps])
  22.             rc(nps, mat, flg, cnt, ++qlt);
  23. }
  24.  
  25. int main()
  26. {
  27.     // Input
  28.     cin.tie(0)->sync_with_stdio(0);
  29.     cout.tie(0)->sync_with_stdio(0);
  30.     long n;
  31.     cin >> n;
  32.     vector<set<long>> mat(n+1);
  33.     for (long i = 1; i <= n; ++i)
  34.         for (long j = 1; j <= n; ++j){
  35.             bool x;
  36.             cin >> x;
  37.             if (x){
  38.                 mat[i].insert(j);
  39.                 mat[j].insert(i);
  40.             }
  41.         }
  42.     // Thuật toán thuần DFS
  43.     vector<long> flg(n+1, 0);
  44.     long cnt = 0, mav = 0;
  45.     for (long i = 1; i <= n; ++i)
  46.         if (!flg[i]){
  47.             long qlt = 1;
  48.             rc(i, mat, flg, ++cnt, qlt);
  49.             mav = (qlt > mav) ? qlt : mav;
  50.         }
  51.     cout << cnt << nln << mav << nln;
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement