Submission #666282

#TimeUsernameProblemLanguageResultExecution timeMemory
666282Chal1shkanCijanobakterije (COCI21_cijanobakterije)C++14
70 / 70
41 ms12108 KiB
# include <bits/stdc++.h> # define pb push_back # define ff first # define ss second # define nl "\n" # define pii pair <int, int> # define pll pair <ll, ll> typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = 1e5 + 125; const ll maxl = 20 + 0; const ll inf = 2e9 + 0; const ll mod = 998244353; using namespace std; ll n, m, vv, uu, cur; vector <ll> g[maxn]; bool used[maxn]; void dfs (ll v, ll pa, ll d, bool tp) { if (d >= cur) { cur = d; if (!tp) vv = v; else uu = v; } used[v] = 1; for (ll to : g[v]) { if (to != pa) { dfs(to, v, d + 1, tp); } } } void ma1n () { cin >> n >> m; for (ll i = 1, u, v; i <= m; ++i) { cin >> u >> v; g[u].pb(v); g[v].pb(u); } ll ans = 0; for (ll i = 1; i <= n; ++i) { if (!used[i]) { cur = 0; dfs(i, i, 1, 0); cur = 0; dfs(vv, vv, 1, 1); ans += cur; // cout << vv << ' ' << uu << nl; } } cout << ans << nl; } int main () { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ttt = 1; // cin >> ttt; for (int test = 1; test <= ttt; test++) { // cout << "Case " << test << ":" << nl; ma1n(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...