Submission #647076

#TimeUsernameProblemLanguageResultExecution timeMemory
647076AlmaCijanobakterije (COCI21_cijanobakterije)C++14
70 / 70
50 ms7500 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second using ll = long long; using ii = pair<int,int>; const int INF = 1e9; const ll LLINF = 1e18; using vi = vector<int>; using vvi = vector<vi>; void setIO (string fileName) { ios::sync_with_stdio(false); cin.tie(NULL); if (fileName != "std") { freopen((fileName + ".in").c_str(), "r", stdin); freopen((fileName + ".out").c_str(), "w", stdout); } } int treeDiameter (vvi& adj, vi& vis, int idx) { int last = idx, dist = 1; queue<ii> bfs; bfs.push({idx, -1}); while (!bfs.empty()) { int u = bfs.front().fi; int p = bfs.front().se; bfs.pop(); last = u; for (int v: adj[u]) { if (v != p) bfs.push({v, u}); } } bfs.push({last, 1}); while (!bfs.empty()) { int u = bfs.front().fi; int d = bfs.front().se; bfs.pop(); dist = d; vis[u] = true; for (int v: adj[u]) { if (!vis[v]) bfs.push({v, d+1}); } } return dist; } int main() { setIO("std"); int n, m, u, v; cin >> n >> m; vvi adj(n); vi vis(n, false); while (m--) { cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); } int ans = 0; for (int i = 0; i < n; i++) { if (!vis[i]) { ans += treeDiameter(adj, vis, i); } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((fileName + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((fileName + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...