답안 #293004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293004 2020-09-07T15:31:47 Z 송준혁(#5803) 서류 전달 (ROI16_sending) C++17
29 / 100
5000 ms 25028 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M;
int ans, ansu=1, ansv=2;
int D[202020], P[202020][20];
int U[202020], V[202020];
vector<int> adj[202020], T[202020];

int LCA(int u, int v){
	if (D[u] > D[v]) swap(u, v);
	for (int i=18; i>=0; i--) if (D[u] <= D[v]-(1<<i)) v=P[v][i];
	if (u == v) return u;
	for (int i=18; i>=0; i--) if (P[u][i] != P[v][i]) u=P[u][i], v=P[v][i];
	return P[u][0];
}

int inter(int u1, int v1, int u2, int v2){
	vector<int> t;
	t.pb(D[LCA(u1, u2)]), t.pb(D[LCA(u1, v2)]);
	t.pb(D[LCA(v1, u2)]), t.pb(D[LCA(v1, v2)]);
	sort(t.begin(), t.end());
	return t[2]+t[3]-2*max(D[LCA(u1, v1)], D[LCA(u2, v2)]);
}

int main(){
	scanf("%d %d", &N, &M);
	for (int i=2; i<=N; i++){
		int p;
		scanf("%d", &p);
		P[i][0] = p, D[i] = D[p]+1;
		for (int j=1; j<=18; j++) P[i][j] = P[P[i][j-1]][j-1];
	}
	for (int i=1; i<=M; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		U[i]=u, V[i]=v;
		int lca = LCA(u, v);
		while (u != lca) T[u].pb(i), u=P[u][0];
		while (v != lca) T[v].pb(i), v=P[v][0];
	}
	for (int i=1; i<=N; i++){
		if (T[i].size() < 2) continue;
		for (int x=0; x<T[i].size(); x++) for (int y=x+1; y<T[i].size(); y++){
			int r = inter(U[T[i][x]], V[T[i][x]], U[T[i][y]], V[T[i][y]]);
			if (ans < r) ans=r, ansu=T[i][x], ansv=T[i][y];
		}
	}
	printf("%d\n%d %d\n", ans, ansu, ansv);
	return 0;
}

Compilation message

sending.cpp: In function 'int main()':
sending.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for (int x=0; x<T[i].size(); x++) for (int y=x+1; y<T[i].size(); y++){
      |                 ~^~~~~~~~~~~~
sending.cpp:47:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for (int x=0; x<T[i].size(); x++) for (int y=x+1; y<T[i].size(); y++){
      |                                                     ~^~~~~~~~~~~~
sending.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |  scanf("%d %d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~
sending.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |   scanf("%d", &p);
      |   ~~~~~^~~~~~~~~~
sending.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9856 KB Output is correct
4 Correct 7 ms 9856 KB Output is correct
5 Correct 6 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 17 ms 9856 KB Output is correct
8 Correct 46 ms 9856 KB Output is correct
9 Correct 62 ms 9976 KB Output is correct
10 Correct 31 ms 9856 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 47 ms 9856 KB Output is correct
13 Correct 8 ms 9856 KB Output is correct
14 Correct 11 ms 9856 KB Output is correct
15 Correct 121 ms 9940 KB Output is correct
16 Correct 28 ms 9856 KB Output is correct
17 Correct 31 ms 9856 KB Output is correct
18 Correct 40 ms 9856 KB Output is correct
19 Correct 33 ms 9856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9856 KB Output is correct
4 Correct 7 ms 9856 KB Output is correct
5 Correct 6 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 17 ms 9856 KB Output is correct
8 Correct 46 ms 9856 KB Output is correct
9 Correct 62 ms 9976 KB Output is correct
10 Correct 31 ms 9856 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 47 ms 9856 KB Output is correct
13 Correct 8 ms 9856 KB Output is correct
14 Correct 11 ms 9856 KB Output is correct
15 Correct 121 ms 9940 KB Output is correct
16 Correct 28 ms 9856 KB Output is correct
17 Correct 31 ms 9856 KB Output is correct
18 Correct 40 ms 9856 KB Output is correct
19 Correct 33 ms 9856 KB Output is correct
20 Correct 720 ms 10364 KB Output is correct
21 Correct 1347 ms 10432 KB Output is correct
22 Execution timed out 5085 ms 16888 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9856 KB Output is correct
4 Correct 7 ms 9856 KB Output is correct
5 Correct 6 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 17 ms 9856 KB Output is correct
8 Correct 46 ms 9856 KB Output is correct
9 Correct 62 ms 9976 KB Output is correct
10 Correct 31 ms 9856 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 47 ms 9856 KB Output is correct
13 Correct 8 ms 9856 KB Output is correct
14 Correct 11 ms 9856 KB Output is correct
15 Correct 121 ms 9940 KB Output is correct
16 Correct 28 ms 9856 KB Output is correct
17 Correct 31 ms 9856 KB Output is correct
18 Correct 40 ms 9856 KB Output is correct
19 Correct 33 ms 9856 KB Output is correct
20 Correct 720 ms 10364 KB Output is correct
21 Correct 1347 ms 10432 KB Output is correct
22 Execution timed out 5085 ms 16888 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9856 KB Output is correct
4 Correct 7 ms 9856 KB Output is correct
5 Correct 6 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 17 ms 9856 KB Output is correct
8 Correct 46 ms 9856 KB Output is correct
9 Correct 62 ms 9976 KB Output is correct
10 Correct 31 ms 9856 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 47 ms 9856 KB Output is correct
13 Correct 8 ms 9856 KB Output is correct
14 Correct 11 ms 9856 KB Output is correct
15 Correct 121 ms 9940 KB Output is correct
16 Correct 28 ms 9856 KB Output is correct
17 Correct 31 ms 9856 KB Output is correct
18 Correct 40 ms 9856 KB Output is correct
19 Correct 33 ms 9856 KB Output is correct
20 Correct 720 ms 10364 KB Output is correct
21 Correct 1347 ms 10432 KB Output is correct
22 Execution timed out 5085 ms 16888 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5047 ms 25028 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5094 ms 21468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9856 KB Output is correct
4 Correct 7 ms 9856 KB Output is correct
5 Correct 6 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 17 ms 9856 KB Output is correct
8 Correct 46 ms 9856 KB Output is correct
9 Correct 62 ms 9976 KB Output is correct
10 Correct 31 ms 9856 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 47 ms 9856 KB Output is correct
13 Correct 8 ms 9856 KB Output is correct
14 Correct 11 ms 9856 KB Output is correct
15 Correct 121 ms 9940 KB Output is correct
16 Correct 28 ms 9856 KB Output is correct
17 Correct 31 ms 9856 KB Output is correct
18 Correct 40 ms 9856 KB Output is correct
19 Correct 33 ms 9856 KB Output is correct
20 Correct 720 ms 10364 KB Output is correct
21 Correct 1347 ms 10432 KB Output is correct
22 Execution timed out 5085 ms 16888 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9856 KB Output is correct
2 Correct 7 ms 9856 KB Output is correct
3 Correct 7 ms 9856 KB Output is correct
4 Correct 7 ms 9856 KB Output is correct
5 Correct 6 ms 9856 KB Output is correct
6 Correct 11 ms 9856 KB Output is correct
7 Correct 17 ms 9856 KB Output is correct
8 Correct 46 ms 9856 KB Output is correct
9 Correct 62 ms 9976 KB Output is correct
10 Correct 31 ms 9856 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 47 ms 9856 KB Output is correct
13 Correct 8 ms 9856 KB Output is correct
14 Correct 11 ms 9856 KB Output is correct
15 Correct 121 ms 9940 KB Output is correct
16 Correct 28 ms 9856 KB Output is correct
17 Correct 31 ms 9856 KB Output is correct
18 Correct 40 ms 9856 KB Output is correct
19 Correct 33 ms 9856 KB Output is correct
20 Correct 720 ms 10364 KB Output is correct
21 Correct 1347 ms 10432 KB Output is correct
22 Execution timed out 5085 ms 16888 KB Time limit exceeded
23 Halted 0 ms 0 KB -