Submission #496535

#TimeUsernameProblemLanguageResultExecution timeMemory
496535kappaCijanobakterije (COCI21_cijanobakterije)C++14
70 / 70
105 ms13892 KiB
#include <bits/stdc++.h> using namespace std; int n, m, ans, vis[100005]; vector<int> d[100005]; pair<int, int> furthest(int ind, int parent = -1){ vis[ind] = 1; pair<int, int> ret(ind, 1); for (int i = 0; i < d[ind].size(); i++) { if(d[ind][i] != parent){ pair<int, int> a = furthest(d[ind][i], ind); a.second++; if(a.second > ret.second){ ret = a; } } } return ret; } int diameter(int ind){ pair<int, int> s1 = furthest(ind); return furthest(s1.first).second; } int main(){ cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; d[u].push_back(v); d[v].push_back(u); } for (int i = 1; i <= n; i++) { if(!vis[i]){ ans += diameter(i); } } cout << ans; }

Compilation message (stderr)

Main.cpp: In function 'std::pair<int, int> furthest(int, int)':
Main.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < d[ind].size(); 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...