Submission #1059531

#TimeUsernameProblemLanguageResultExecution timeMemory
1059531ThanhsCijanobakterije (COCI21_cijanobakterije)C++14
70 / 70
35 ms19660 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define endl '\n' #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) #define fi first #define se second #define all(x) x.begin(), x.end() // mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); // int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 1e5 + 5; const int LM = 1e4 + 5; const int mod = 1e9 + 7; vector<int> g[NM]; vector<pair<int, int>> V; int ans, n, m, dep[NM], d, vis[NM]; void dfs(int u, int p = 0) { vis[u] = 1; V.push_back({dep[u], u}); for (int v : g[u]) if (v != p) { dep[v] = dep[u] + 1; dfs(v, u); } } void DFS(int u, int l, int p = 0) { setmax(d, l); for (int v : g[u]) if (v != p) DFS(v, l + 1, u); } void solve() { cin >> n >> m; while (m--) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } for (int i = 1; i <= n; i++) if (!vis[i]) { V.clear(); dfs(i); int u = (*max_element(V.begin(), V.end())).se; d = 1; DFS(u, 1); ans += d; } cout << ans << endl; } signed main() { fastIO if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } int tc = 1; // cin >> tc; while (tc--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen("out.txt", "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...