Submission #1268734

#TimeUsernameProblemLanguageResultExecution timeMemory
1268734ilovewaguriCijanobakterije (COCI21_cijanobakterije)C++20
70 / 70
26 ms12100 KiB
#include<bits/stdc++.h> using namespace std; #define NAME "CHAIN" #define nl '\n' #define allofa(x,sz) x,x+sz+1 #define allof(x) x.begin(),x.end() #define allof1(x) x.begin()+1,x.end() #define mset(x,val) memset(x,val,sizeof(x)) #define couf(x) cout << fixed << setprecision(x) template<class T> T Abs(T &x) {return (x>=0 ? x : -x);}; template<class X,class Y> bool minimize(X &a, Y b){if(a>b) {a=b;return true;}return false;}; template<class X,class Y> bool maximize(X &a, Y b){if(a<b) {a=b;return true;}return false;}; typedef long long ll; const ll mod = (long long)1e9+7; const ll LINF = (long long)1e15; const int INF = (int)1e9; const int MAXN = (int)1e5+5; vector<int> graph[MAXN]; bool visited[MAXN]; int n,m; void ccps() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if(fopen(NAME".inp","r")) { freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } } pair<int,int> dfs(int u, int pre) { visited[u] = true; pair<int,int> ret(u,1); for (int v : graph[u]) { if(v^pre) { pair<int,int> sub = dfs(v,u); sub.second++; if(maximize(ret.second,sub.second)) { ret = sub; } } } return ret; } int calc(int node) { int far = dfs(node,-1).first; return dfs(far,-1).second; } signed main() { ccps(); cin >> n >> m; mset(visited,false); int res = 0; for (int i = 1; i<=m; i++) { int u,v; cin >> u >> v; graph[u].push_back(v); graph[v].push_back(u); } for (int u = 1; u<=n; u++) { if(!visited[u]) { res+=calc(u); } } cout << res; }

Compilation message (stderr)

Main.cpp: In function 'void ccps()':
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(NAME".out","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...