답안 #441257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441257 2021-07-04T18:47:07 Z cheetose Meetings 2 (JOI21_meetings2) C++17
20 / 100
4000 ms 26412 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<db, db> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

Vi v[200001];
Vi vv[200001];
int dist[200001];
int bfs(int N){
	MEM_1(dist);
	queue<int> q;
	q.push(N);
	dist[N]=0;
	int last;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		last=x;
		for(int y:vv[x]){
			if(dist[y]==-1){
				dist[y]=dist[x]+1;
				q.push(y);
			}
		}
	}
	return last;
}
int get_dia(int N){
	int t=bfs(N);
	t=bfs(t);
	return dist[t];
}
int cnt[200001];
void dfs(int N,int p=-1){
	cnt[N]=1;
	for(int next:v[N]){
		if(next==p)continue;
		dfs(next,N);
		cnt[N]+=cnt[next];
	}
}
int cc,n;
void dfs2(int N,int k,int p=-1){
	for(int next:v[N]){
		if(next==p)continue;
		if(cnt[next]>=k && n-cnt[next]>=k){
			cc=N;
			vv[N].pb(next);
			vv[next].pb(N);
		}
		dfs2(next,k,N);
	}
}
int main(){
	scanf("%d",&n);
	fup(i,1,n-1,1){
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(1);
	fup(i,1,n,1){
		if(i&1)puts("1");
		else{
			fup(ii,1,n,1)vv[ii].clear();
			dfs2(1,i/2);
			printf("%d\n",get_dia(cc)+1);
		}
	}
}

Compilation message

meetings2.cpp: In function 'int main()':
meetings2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
meetings2.cpp:93:2: note: in expansion of macro 'fup'
   93 |  fup(i,1,n-1,1){
      |  ^~~
meetings2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
meetings2.cpp:100:2: note: in expansion of macro 'fup'
  100 |  fup(i,1,n,1){
      |  ^~~
meetings2.cpp:10:30: warning: unnecessary parentheses in declaration of 'ii' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
meetings2.cpp:103:4: note: in expansion of macro 'fup'
  103 |    fup(ii,1,n,1)vv[ii].clear();
      |    ^~~
meetings2.cpp:92:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
meetings2.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
meetings2.cpp: In function 'int bfs(int)':
meetings2.cpp:63:9: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |  return last;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 10444 KB Output is correct
3 Correct 6 ms 10444 KB Output is correct
4 Correct 6 ms 10444 KB Output is correct
5 Correct 7 ms 10432 KB Output is correct
6 Correct 7 ms 10392 KB Output is correct
7 Correct 6 ms 10444 KB Output is correct
8 Correct 6 ms 10444 KB Output is correct
9 Correct 8 ms 10432 KB Output is correct
10 Correct 7 ms 10444 KB Output is correct
11 Correct 7 ms 10444 KB Output is correct
12 Correct 7 ms 10444 KB Output is correct
13 Correct 7 ms 10444 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 7 ms 10572 KB Output is correct
17 Correct 7 ms 10444 KB Output is correct
18 Correct 7 ms 10444 KB Output is correct
19 Correct 7 ms 10464 KB Output is correct
20 Correct 7 ms 10388 KB Output is correct
21 Correct 7 ms 10444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 10444 KB Output is correct
3 Correct 6 ms 10444 KB Output is correct
4 Correct 6 ms 10444 KB Output is correct
5 Correct 7 ms 10432 KB Output is correct
6 Correct 7 ms 10392 KB Output is correct
7 Correct 6 ms 10444 KB Output is correct
8 Correct 6 ms 10444 KB Output is correct
9 Correct 8 ms 10432 KB Output is correct
10 Correct 7 ms 10444 KB Output is correct
11 Correct 7 ms 10444 KB Output is correct
12 Correct 7 ms 10444 KB Output is correct
13 Correct 7 ms 10444 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 7 ms 10572 KB Output is correct
17 Correct 7 ms 10444 KB Output is correct
18 Correct 7 ms 10444 KB Output is correct
19 Correct 7 ms 10464 KB Output is correct
20 Correct 7 ms 10388 KB Output is correct
21 Correct 7 ms 10444 KB Output is correct
22 Correct 285 ms 10780 KB Output is correct
23 Correct 289 ms 10824 KB Output is correct
24 Correct 282 ms 10784 KB Output is correct
25 Correct 282 ms 10780 KB Output is correct
26 Correct 286 ms 10780 KB Output is correct
27 Correct 286 ms 10700 KB Output is correct
28 Correct 293 ms 10824 KB Output is correct
29 Correct 292 ms 10700 KB Output is correct
30 Correct 288 ms 10736 KB Output is correct
31 Correct 302 ms 10700 KB Output is correct
32 Correct 428 ms 11060 KB Output is correct
33 Correct 456 ms 11076 KB Output is correct
34 Correct 252 ms 10820 KB Output is correct
35 Correct 212 ms 10944 KB Output is correct
36 Correct 240 ms 10700 KB Output is correct
37 Correct 212 ms 10828 KB Output is correct
38 Correct 289 ms 10904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 10444 KB Output is correct
3 Correct 6 ms 10444 KB Output is correct
4 Correct 6 ms 10444 KB Output is correct
5 Correct 7 ms 10432 KB Output is correct
6 Correct 7 ms 10392 KB Output is correct
7 Correct 6 ms 10444 KB Output is correct
8 Correct 6 ms 10444 KB Output is correct
9 Correct 8 ms 10432 KB Output is correct
10 Correct 7 ms 10444 KB Output is correct
11 Correct 7 ms 10444 KB Output is correct
12 Correct 7 ms 10444 KB Output is correct
13 Correct 7 ms 10444 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 7 ms 10572 KB Output is correct
17 Correct 7 ms 10444 KB Output is correct
18 Correct 7 ms 10444 KB Output is correct
19 Correct 7 ms 10464 KB Output is correct
20 Correct 7 ms 10388 KB Output is correct
21 Correct 7 ms 10444 KB Output is correct
22 Correct 285 ms 10780 KB Output is correct
23 Correct 289 ms 10824 KB Output is correct
24 Correct 282 ms 10784 KB Output is correct
25 Correct 282 ms 10780 KB Output is correct
26 Correct 286 ms 10780 KB Output is correct
27 Correct 286 ms 10700 KB Output is correct
28 Correct 293 ms 10824 KB Output is correct
29 Correct 292 ms 10700 KB Output is correct
30 Correct 288 ms 10736 KB Output is correct
31 Correct 302 ms 10700 KB Output is correct
32 Correct 428 ms 11060 KB Output is correct
33 Correct 456 ms 11076 KB Output is correct
34 Correct 252 ms 10820 KB Output is correct
35 Correct 212 ms 10944 KB Output is correct
36 Correct 240 ms 10700 KB Output is correct
37 Correct 212 ms 10828 KB Output is correct
38 Correct 289 ms 10904 KB Output is correct
39 Execution timed out 4062 ms 26412 KB Time limit exceeded
40 Halted 0 ms 0 KB -