Advertisement
limimage

seti_2

Mar 2nd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define endl "\n"
  4. using namespace std;
  5. using ll = long long;
  6. using ld = long double;
  7. using pii = pair<int, int>;
  8.  
  9. constexpr int N = 1e2 + 5;
  10.  
  11. vector<int> gr[N];
  12. vector<bool> used;
  13. int dist[N][N];
  14. string s;
  15.  
  16. int find_diam() {
  17. for (int k = 0; k < N; k++)
  18. for (int i = 0; i < N; i++)
  19. for (int j = 0; j < N; j++)
  20. if (i != j && j != k && i != k)
  21. dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  22. int ans = 0;
  23. for (int i = 0; i < N; i++)
  24. for (int j = 0; j < N; j++)
  25. ans = max(dist[i][j] == N ? 0: dist[i][j], ans);
  26. return ans;
  27. }
  28.  
  29. void add_edge(int a, int b) {
  30. dist[a][b] = 1;
  31. dist[b][a] = 1;
  32. }
  33.  
  34. void Solve() {
  35. fill(&dist[0][0], &dist[N - 1][N], N);
  36. getline(cin, s);
  37. for (int i = 0; i < s.size();) {
  38. while(i < s.size() && !isdigit(s[i]))
  39. i++;
  40. string n1, n2;
  41. while(i < s.size() && isdigit(s[i]))
  42. n1.push_back(s[i]), i++;
  43. while(i < s.size() && !isdigit(s[i]))
  44. i++;
  45. while(i < s.size() && isdigit(s[i]))
  46. n2.push_back(s[i]), i++;
  47. if (n1.size() && n2.size())
  48. add_edge(stoi(n1), stoi(n2));
  49. }
  50. cout << find_diam();
  51. }
  52.  
  53. int main() {
  54. ios::sync_with_stdio(false);
  55. cin.tie(nullptr);
  56. cout.tie(nullptr);
  57. //auto start = chrono::high_resolution_clock::now();
  58. Solve();
  59. //auto end = chrono::high_resolution_clock::now();
  60. //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement