답안 #293062

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

int N, M;
int ans, ansu=1, ansv=2;
int D[202020];
pii A[202020], B[202020];
vector<int> adj[202020];

void dfs(int u){
	for (int v : adj[u]){
		dfs(v);
		if (A[u] > A[v]) B[u] = A[u], A[u] = A[v];
		else B[u] = min(B[u], A[v]);
	}
	if (ans < D[u]-B[u].fi) ans = D[u]-B[u].fi, ansu=A[u].se, ansv=B[u].se;
}

int main(){
	scanf("%d %d", &N, &M);
	A[1] = B[1] = pii(N, 0);
	for (int i=2; i<=N; i++){
		int p;
		scanf("%d", &p);
		D[i] = D[p] + 1;
		adj[p].pb(i);
		A[i] = B[i] = pii(N, 0);
	}
	for (int i=1; i<=M; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		if (D[u] > D[v]) swap(u, v);
		if (A[v] > pii(D[u], i)) B[v] = A[v], A[v] = pii(D[u], i);
		else B[v] = min(B[v], pii(D[u], i));
	}
	dfs(1);
	printf("%d\n%d %d\n", ans, ansu, ansv);
	return 0;
}

Compilation message

sending.cpp: In function 'int main()':
sending.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |  scanf("%d %d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~
sending.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |   scanf("%d", &p);
      |   ~~~~~^~~~~~~~~~
sending.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Incorrect 4 ms 5120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Incorrect 4 ms 5120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Incorrect 4 ms 5120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Incorrect 4 ms 5120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 8592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 8696 KB Output is correct
2 Correct 69 ms 8832 KB Output is correct
3 Correct 51 ms 16376 KB Output is correct
4 Correct 63 ms 13304 KB Output is correct
5 Correct 48 ms 11768 KB Output is correct
6 Correct 34 ms 7544 KB Output is correct
7 Correct 58 ms 16376 KB Output is correct
8 Correct 36 ms 7680 KB Output is correct
9 Correct 59 ms 8568 KB Output is correct
10 Correct 42 ms 16376 KB Output is correct
11 Correct 38 ms 16380 KB Output is correct
12 Correct 39 ms 16384 KB Output is correct
13 Correct 53 ms 16416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Incorrect 4 ms 5120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Incorrect 4 ms 5120 KB Output isn't correct
4 Halted 0 ms 0 KB -