답안 #537921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537921 2022-03-15T21:50:36 Z inksamurai Cijanobakterije (COCI21_cijanobakterije) C++17
70 / 70
61 ms 11100 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3HspL4A ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vec(int);
void print(){cout<<"\n";}
template<class T,class...E>
void print(const T&v,const E&...u){cout<<v<<' ',print(u...);}
// e

signed main(){
_3HspL4A;
	int n,m;
	cin>>n>>m;
	vec(vi) adj(n);
	rep(i,m){
		int u,v;
		cin>>u>>v;
		u-=1,v-=1;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	vi usd(n,0);
	int now=0;

	auto dfs=[&](auto self,int v)->int{
		usd[v]=1;
		pii p={0,0};
		for(auto u:adj[v]){
			if(!usd[u]){
				int val=self(self,u);
				if(val>p.fi){
					p.se=p.fi;
					p.fi=val;
				}else if(val>p.se){
					p.se=val;
				}
			}
		}
		now=max(now,p.fi+p.se+1);
		return p.fi+1;
	};

	int ans=0;
	rep(v,n)if(!usd[v]){
		now=0;
		dfs(dfs,v);
		ans+=now;
	}
	print(ans);
//
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1456 KB Output is correct
2 Correct 12 ms 2636 KB Output is correct
3 Correct 19 ms 3836 KB Output is correct
4 Correct 29 ms 4980 KB Output is correct
5 Correct 61 ms 6224 KB Output is correct
6 Correct 43 ms 7340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 11100 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 6 ms 2208 KB Output is correct
4 Correct 8 ms 3144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 4 ms 1356 KB Output is correct
6 Correct 6 ms 2388 KB Output is correct
7 Correct 9 ms 3424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1456 KB Output is correct
2 Correct 12 ms 2636 KB Output is correct
3 Correct 19 ms 3836 KB Output is correct
4 Correct 29 ms 4980 KB Output is correct
5 Correct 61 ms 6224 KB Output is correct
6 Correct 43 ms 7340 KB Output is correct
7 Correct 27 ms 11100 KB Output is correct
8 Correct 3 ms 1236 KB Output is correct
9 Correct 6 ms 2208 KB Output is correct
10 Correct 8 ms 3144 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 4 ms 1356 KB Output is correct
16 Correct 6 ms 2388 KB Output is correct
17 Correct 9 ms 3424 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 45 ms 7332 KB Output is correct
30 Correct 8 ms 4052 KB Output is correct
31 Correct 26 ms 6900 KB Output is correct
32 Correct 17 ms 4972 KB Output is correct
33 Correct 33 ms 7212 KB Output is correct
34 Correct 26 ms 5516 KB Output is correct
35 Correct 29 ms 6948 KB Output is correct
36 Correct 26 ms 6200 KB Output is correct
37 Correct 30 ms 7096 KB Output is correct
38 Correct 41 ms 6716 KB Output is correct
39 Correct 31 ms 7012 KB Output is correct