Submission #900583

#TimeUsernameProblemLanguageResultExecution timeMemory
900583HamzaTCijanobakterije (COCI21_cijanobakterije)C++14
70 / 70
37 ms19924 KiB
//struct Edge {int u, v, weight;bool operator<(Edge const& other) {return weight < other.weight;}}; #include <bits/stdc++.h> #define endl "\n" #define ll long long #define sp ' ' #define pb push_back #define ar for(int i=1;i<=n;i++) using namespace std; ll t=1; const ll N=3e5+100; ll n,m,q,k; ll a[N],b[N],c[N]; bool vis[N]; ll mx=0; ll ans=0; ll last; vector<int>vnum; vector<int>v[N]; void dfs(ll x,ll y) { vnum.push_back(x); vis[x]=1; if(mx<y){ mx=max(mx,y);last=x;} for(auto i:v[x]) { if(!vis[i]){dfs(i,y+1);} } } void solve() { cin>>n>>m; while(m--) { ll x,y;cin>>x>>y; v[x].push_back(y); v[y].push_back(x); } for(int i=1;i<=n;i++) { if(!vis[i]) { vnum.clear(); mx=0; last=0; dfs(i,1); mx=0; if(last==0){continue;} for(auto i:vnum){vis[i]=0;} dfs(last,1); ans+=mx; } } cout<<ans<<endl;return; } int main() { //freopen("shell.in", "r", stdin); // freopen("shell.out", "w", stdout); ios::sync_with_stdio(NULL); cin.tie(NULL);cout.tie(NULL); // cin>>t; while(t--){solve();} return 0; } //09:00 :: 9:45 //10:30 ::
#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...