Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using ld = long double;
- using pii = pair<int, int>;
- constexpr int N = 1e2 + 5;
- vector<int> gr[N];
- vector<bool> used;
- int dist[N][N];
- string s;
- int find_diam() {
- for (int k = 0; k < N; k++)
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- if (i != j && j != k && i != k)
- dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
- int ans = 0;
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- ans = max(dist[i][j] == N ? 0: dist[i][j], ans);
- return ans;
- }
- void add_edge(int a, int b) {
- dist[a][b] = 1;
- dist[b][a] = 1;
- }
- void Solve() {
- fill(&dist[0][0], &dist[N - 1][N], N);
- getline(cin, s);
- for (int i = 0; i < s.size();) {
- while(i < s.size() && !isdigit(s[i]))
- i++;
- string n1, n2;
- while(i < s.size() && isdigit(s[i]))
- n1.push_back(s[i]), i++;
- while(i < s.size() && !isdigit(s[i]))
- i++;
- while(i < s.size() && isdigit(s[i]))
- n2.push_back(s[i]), i++;
- if (n1.size() && n2.size())
- add_edge(stoi(n1), stoi(n2));
- }
- cout << find_diam();
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- //auto start = chrono::high_resolution_clock::now();
- Solve();
- //auto end = chrono::high_resolution_clock::now();
- //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement