This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n, m, mxnode, maxd;
vector<int> g[100001];
bool vis[100001];
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for(register int i = 1, u, v; i <= m; ++i){
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
function<void(int, int, bool, int)> Dfs = [&](int node,int len, bool f, int fa){
if(f) vis[node] = true;
if(maxd < len){
maxd = len, mxnode = node;
}
for(int &to : g[node]){
if(vis[to] || to == fa) continue;
Dfs(to, len + 1, f, node);
}
return;
};
int ans(0);
for(register int i = 1; i <= n; ++i){
if(vis[i]) continue;
maxd = 0;
Dfs(i, 0, 0, i);
Dfs(mxnode, 0, 1, mxnode);
ans += maxd + 1;
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:11:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
11 | for(register int i = 1, u, v; i <= m; ++i){
| ^
Main.cpp:11:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
11 | for(register int i = 1, u, v; i <= m; ++i){
| ^
Main.cpp:11:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
11 | for(register int i = 1, u, v; i <= m; ++i){
| ^
Main.cpp:28:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
28 | for(register int i = 1; i <= n; ++i){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |