제출 #520414

#제출 시각아이디문제언어결과실행 시간메모리
520414LalicCijanobakterije (COCI21_cijanobakterije)C++17
70 / 70
894 ms12396 KiB
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pii; const double pi = 3.14159265358979323846; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 10; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; int d, aux, cmp[MAXN], mark[MAXN]; vector<int> v[MAXN]; void dfs(int x, int dist){ cmp[x]=1; mark[x]=1; if(dist>d){ aux=x; d=dist; } for(auto u : v[x]){ if(cmp[u]==0) dfs(u, dist+1); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int ans=0, n, m; cin >> n >> m; for(int i=0;i<m;i++){ int u, a; cin >> u >> a; v[u].pb(a); v[a].pb(u); } for(int i=1;i<=n;i++){ if(mark[i]==0){ d=-1, aux=-1; memset(cmp, 0, sizeof cmp); dfs(i, 0); if(d==0){ ans++; continue; } d=-1; memset(cmp, 0, sizeof cmp); dfs(aux, 0); d++; ans+=d; } } cout << ans << "\n"; return 0; }
#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...