# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
679394 | 2023-01-08T08:08:46 Z | Warinchai | Cijanobakterije (COCI21_cijanobakterije) | C++14 | 118 ms | 23756 KB |
#include<bits/stdc++.h> using namespace std; vector<int>v[100005]; int p[100005]; int soch[100005][2]; bool vis[100005]; priority_queue<int>pq[100005]; vector<int>pr; int mxl[100005]; int dfs(int nd,int par){ for(int i=0;i<v[nd].size();i++){ if(vis[v[nd][i]]==0){ vis[v[nd][i]]=1; pq[nd].push(dfs(v[nd][i],par)); } } if(!pq[nd].empty()){ soch[nd][0]=pq[nd].top(); pq[nd].pop(); } if(!pq[nd].empty()){ soch[nd][1]=pq[nd].top(); } if(soch[nd][0]+soch[nd][1]+1>mxl[par]){ mxl[par]=soch[nd][0]+soch[nd][1]+1; } return soch[nd][0]+1; } int fp(int a){ if(p[a]==a){ return a; } p[a]=fp(p[a]); return p[a]; } void un(int a,int b){ if(fp(a)==fp(b)){ return; } p[fp(a)]=fp(b); } int main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ p[i]=i; } for(int i=0;i<m;i++){ int a,b; cin>>a>>b; v[a].push_back(b); v[b].push_back(a); un(a,b); } for(int i=1;i<=n;i++){ if(fp(i)==i){ pr.push_back(i); } } int ans=0; for(int i=0;i<pr.size();i++){ int nd=pr[i]; vis[nd]=1; dfs(nd,nd); ans+=mxl[nd]; } cout<<ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 6996 KB | Output is correct |
2 | Correct | 31 ms | 8172 KB | Output is correct |
3 | Correct | 48 ms | 9396 KB | Output is correct |
4 | Correct | 66 ms | 10556 KB | Output is correct |
5 | Correct | 87 ms | 11848 KB | Output is correct |
6 | Correct | 118 ms | 13004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 72 ms | 23756 KB | Output is correct |
2 | Correct | 8 ms | 6868 KB | Output is correct |
3 | Correct | 15 ms | 7800 KB | Output is correct |
4 | Correct | 22 ms | 8956 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5716 KB | Output is correct |
2 | Correct | 3 ms | 5716 KB | Output is correct |
3 | Correct | 3 ms | 5804 KB | Output is correct |
4 | Correct | 3 ms | 5796 KB | Output is correct |
5 | Correct | 10 ms | 6672 KB | Output is correct |
6 | Correct | 17 ms | 7508 KB | Output is correct |
7 | Correct | 24 ms | 8576 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5844 KB | Output is correct |
2 | Correct | 3 ms | 5716 KB | Output is correct |
3 | Correct | 3 ms | 5716 KB | Output is correct |
4 | Correct | 3 ms | 5844 KB | Output is correct |
5 | Correct | 3 ms | 5796 KB | Output is correct |
6 | Correct | 4 ms | 5844 KB | Output is correct |
7 | Correct | 3 ms | 5844 KB | Output is correct |
8 | Correct | 3 ms | 5844 KB | Output is correct |
9 | Correct | 3 ms | 5844 KB | Output is correct |
10 | Correct | 4 ms | 5844 KB | Output is correct |
11 | Correct | 4 ms | 5844 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 6996 KB | Output is correct |
2 | Correct | 31 ms | 8172 KB | Output is correct |
3 | Correct | 48 ms | 9396 KB | Output is correct |
4 | Correct | 66 ms | 10556 KB | Output is correct |
5 | Correct | 87 ms | 11848 KB | Output is correct |
6 | Correct | 118 ms | 13004 KB | Output is correct |
7 | Correct | 72 ms | 23756 KB | Output is correct |
8 | Correct | 8 ms | 6868 KB | Output is correct |
9 | Correct | 15 ms | 7800 KB | Output is correct |
10 | Correct | 22 ms | 8956 KB | Output is correct |
11 | Correct | 3 ms | 5716 KB | Output is correct |
12 | Correct | 3 ms | 5716 KB | Output is correct |
13 | Correct | 3 ms | 5804 KB | Output is correct |
14 | Correct | 3 ms | 5796 KB | Output is correct |
15 | Correct | 10 ms | 6672 KB | Output is correct |
16 | Correct | 17 ms | 7508 KB | Output is correct |
17 | Correct | 24 ms | 8576 KB | Output is correct |
18 | Correct | 3 ms | 5844 KB | Output is correct |
19 | Correct | 3 ms | 5716 KB | Output is correct |
20 | Correct | 3 ms | 5716 KB | Output is correct |
21 | Correct | 3 ms | 5844 KB | Output is correct |
22 | Correct | 3 ms | 5796 KB | Output is correct |
23 | Correct | 4 ms | 5844 KB | Output is correct |
24 | Correct | 3 ms | 5844 KB | Output is correct |
25 | Correct | 3 ms | 5844 KB | Output is correct |
26 | Correct | 3 ms | 5844 KB | Output is correct |
27 | Correct | 4 ms | 5844 KB | Output is correct |
28 | Correct | 4 ms | 5844 KB | Output is correct |
29 | Correct | 99 ms | 13056 KB | Output is correct |
30 | Correct | 19 ms | 9296 KB | Output is correct |
31 | Correct | 63 ms | 12984 KB | Output is correct |
32 | Correct | 49 ms | 10444 KB | Output is correct |
33 | Correct | 77 ms | 13180 KB | Output is correct |
34 | Correct | 53 ms | 11360 KB | Output is correct |
35 | Correct | 67 ms | 13016 KB | Output is correct |
36 | Correct | 70 ms | 12136 KB | Output is correct |
37 | Correct | 77 ms | 13172 KB | Output is correct |
38 | Correct | 78 ms | 12820 KB | Output is correct |
39 | Correct | 69 ms | 13024 KB | Output is correct |