Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <bits/stdc++.h>
- #define DB(x) cerr << #x << " is " << (x) << endl;
- #define FIO ios::sync_with_stdio(false);// cin.tie(nullptr); cout.tie(nullptr) // === === === === === === ===>
- #define pb push_back
- #define fs first
- #define sc second
- #define endl "\n"
- typedef long long ll;
- typedef long double ld;
- int const mxn = 2e3+2;
- int const mod = 1e9+7;
- int n, m, ans=-1;
- vector<int> E[mxn];
- vector<int> dd(mxn);
- queue<int> Q;
- int cal(int u){
- Q.push(u);
- dd[u] = 1;
- while (Q.size()){
- u = Q.front();
- Q.pop();
- for (auto v: E[u]){
- if (dd[v]) continue;
- dd[v] = dd[u]+1;
- Q.push(v);
- }
- }
- int f = 0, mx = 0;
- for (int i=1; i<=n; ++i){
- if (!dd[i]) f = 1;
- mx = max(mx,dd[i]);
- dd[i] = 0;
- }
- if (f) return -1;
- return mx;
- }
- void SOL(){
- cin >> n >> m;
- for (int i=1; i<=m; ++i){
- int x, y; cin >> x >> y;
- E[x].pb(y);
- E[y].pb(x);
- }
- for (int i=1; i<=n; ++i){
- ans = max(ans,cal(i));
- }
- if (ans == -1){
- cout << "=[";
- } else {
- cout << "=] " << ans-1;
- }
- }
- /*
- */
- int main(){FIO; SOL(); return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement