Submission #676268

#TimeUsernameProblemLanguageResultExecution timeMemory
676268TangirkulCijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
51 ms11780 KiB
#include<bits/stdc++.h> #define ll long long #define fi first #define se second #define pb push_back #define sz size #define Junanna ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll K = 32; const ll INF = 1e9 + 7; const ll MOD = 1e9 + 7; const ll N = (1e5 + 125); ll n, m; vector <ll> g[N]; bool used[N], used1[N]; pair <ll, ll> ans; void dfs (ll v, ll d) { if (d > ans.fi) { ans = {d, v}; } used[v] = 1; for (ll i = 0; i < g[v].sz (); i++) { ll to = g[v][i]; if (!used[to]) { dfs (to, d + 1); } } } void dfss (ll v, ll d) { if (d > ans.fi) { ans = {d, v}; } used1[v] = 1; for (ll i = 0; i < g[v].sz (); i++) { ll to = g[v][i]; if (!used1[to]) { dfss (to, d + 1); } } } void ma1n () { cin >> n >> m; for (ll i = 1; i <= m; i++) { ll x, y; cin >> x >> y; g[x].pb (y); g[y].pb (x); } ll dis = 0; for (ll i = 1; i <= n; i++) { if (!used[i]) { dfs (i, 1); ans.fi = 0; dfss (ans.se, 1); dis += ans.fi; ans = {0, 0}; } } cout << dis; } int main () { Junanna; ll t = 1; while (t--) { ma1n (); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'void dfs(long long int, long long int)':
Main.cpp:29:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (ll i = 0; i < g[v].sz (); i++)
      |                    ~~^~~~~~~~~~~~
Main.cpp: In function 'void dfss(long long int, long long int)':
Main.cpp:46:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (ll i = 0; i < g[v].sz (); i++)
      |                    ~~^~~~~~~~~~~~
#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...