Submission #293021

# Submission time Handle Problem Language Result Execution time Memory
293021 2020-09-07T15:36:46 Z 송준혁(#5803) ROI16_sending (ROI16_sending) C++17
29 / 100
5000 ms 251232 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];
set<pii> chk;

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 a = T[i][x], b = T[i][y];
			if (a > b) swap(a, b);
			if (chk.find(pii(a,b)) != chk.end()) continue;
			chk.insert(pii(a, b));
			int r = inter(U[a], V[a], U[b], V[b]);
			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:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for (int x=0; x<T[i].size(); x++) for (int y=x+1; y<T[i].size(); y++){
      |                 ~^~~~~~~~~~~~
sending.cpp:48:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for (int x=0; x<T[i].size(); x++) for (int y=x+1; y<T[i].size(); y++){
      |                                                     ~^~~~~~~~~~~~
sending.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |  scanf("%d %d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~
sending.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   scanf("%d", &p);
      |   ~~~~~^~~~~~~~~~
sending.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 7 ms 9856 KB Output is correct
6 Correct 11 ms 9984 KB Output is correct
7 Correct 12 ms 9984 KB Output is correct
8 Correct 16 ms 9984 KB Output is correct
9 Correct 18 ms 9984 KB Output is correct
10 Correct 14 ms 9984 KB Output is correct
11 Correct 8 ms 9856 KB Output is correct
12 Correct 19 ms 9984 KB Output is correct
13 Correct 10 ms 9984 KB Output is correct
14 Correct 11 ms 9984 KB Output is correct
15 Correct 33 ms 10112 KB Output is correct
16 Correct 10 ms 9856 KB Output is correct
17 Correct 10 ms 9856 KB Output is correct
18 Correct 15 ms 9984 KB Output is correct
19 Correct 13 ms 10112 KB Output is correct
# Verdict Execution time Memory 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 7 ms 9856 KB Output is correct
6 Correct 11 ms 9984 KB Output is correct
7 Correct 12 ms 9984 KB Output is correct
8 Correct 16 ms 9984 KB Output is correct
9 Correct 18 ms 9984 KB Output is correct
10 Correct 14 ms 9984 KB Output is correct
11 Correct 8 ms 9856 KB Output is correct
12 Correct 19 ms 9984 KB Output is correct
13 Correct 10 ms 9984 KB Output is correct
14 Correct 11 ms 9984 KB Output is correct
15 Correct 33 ms 10112 KB Output is correct
16 Correct 10 ms 9856 KB Output is correct
17 Correct 10 ms 9856 KB Output is correct
18 Correct 15 ms 9984 KB Output is correct
19 Correct 13 ms 10112 KB Output is correct
20 Correct 456 ms 23596 KB Output is correct
21 Correct 619 ms 25440 KB Output is correct
22 Execution timed out 5050 ms 22740 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 7 ms 9856 KB Output is correct
6 Correct 11 ms 9984 KB Output is correct
7 Correct 12 ms 9984 KB Output is correct
8 Correct 16 ms 9984 KB Output is correct
9 Correct 18 ms 9984 KB Output is correct
10 Correct 14 ms 9984 KB Output is correct
11 Correct 8 ms 9856 KB Output is correct
12 Correct 19 ms 9984 KB Output is correct
13 Correct 10 ms 9984 KB Output is correct
14 Correct 11 ms 9984 KB Output is correct
15 Correct 33 ms 10112 KB Output is correct
16 Correct 10 ms 9856 KB Output is correct
17 Correct 10 ms 9856 KB Output is correct
18 Correct 15 ms 9984 KB Output is correct
19 Correct 13 ms 10112 KB Output is correct
20 Correct 456 ms 23596 KB Output is correct
21 Correct 619 ms 25440 KB Output is correct
22 Execution timed out 5050 ms 22740 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 7 ms 9856 KB Output is correct
6 Correct 11 ms 9984 KB Output is correct
7 Correct 12 ms 9984 KB Output is correct
8 Correct 16 ms 9984 KB Output is correct
9 Correct 18 ms 9984 KB Output is correct
10 Correct 14 ms 9984 KB Output is correct
11 Correct 8 ms 9856 KB Output is correct
12 Correct 19 ms 9984 KB Output is correct
13 Correct 10 ms 9984 KB Output is correct
14 Correct 11 ms 9984 KB Output is correct
15 Correct 33 ms 10112 KB Output is correct
16 Correct 10 ms 9856 KB Output is correct
17 Correct 10 ms 9856 KB Output is correct
18 Correct 15 ms 9984 KB Output is correct
19 Correct 13 ms 10112 KB Output is correct
20 Correct 456 ms 23596 KB Output is correct
21 Correct 619 ms 25440 KB Output is correct
22 Execution timed out 5050 ms 22740 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5056 ms 204856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5101 ms 251232 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 7 ms 9856 KB Output is correct
6 Correct 11 ms 9984 KB Output is correct
7 Correct 12 ms 9984 KB Output is correct
8 Correct 16 ms 9984 KB Output is correct
9 Correct 18 ms 9984 KB Output is correct
10 Correct 14 ms 9984 KB Output is correct
11 Correct 8 ms 9856 KB Output is correct
12 Correct 19 ms 9984 KB Output is correct
13 Correct 10 ms 9984 KB Output is correct
14 Correct 11 ms 9984 KB Output is correct
15 Correct 33 ms 10112 KB Output is correct
16 Correct 10 ms 9856 KB Output is correct
17 Correct 10 ms 9856 KB Output is correct
18 Correct 15 ms 9984 KB Output is correct
19 Correct 13 ms 10112 KB Output is correct
20 Correct 456 ms 23596 KB Output is correct
21 Correct 619 ms 25440 KB Output is correct
22 Execution timed out 5050 ms 22740 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 7 ms 9856 KB Output is correct
6 Correct 11 ms 9984 KB Output is correct
7 Correct 12 ms 9984 KB Output is correct
8 Correct 16 ms 9984 KB Output is correct
9 Correct 18 ms 9984 KB Output is correct
10 Correct 14 ms 9984 KB Output is correct
11 Correct 8 ms 9856 KB Output is correct
12 Correct 19 ms 9984 KB Output is correct
13 Correct 10 ms 9984 KB Output is correct
14 Correct 11 ms 9984 KB Output is correct
15 Correct 33 ms 10112 KB Output is correct
16 Correct 10 ms 9856 KB Output is correct
17 Correct 10 ms 9856 KB Output is correct
18 Correct 15 ms 9984 KB Output is correct
19 Correct 13 ms 10112 KB Output is correct
20 Correct 456 ms 23596 KB Output is correct
21 Correct 619 ms 25440 KB Output is correct
22 Execution timed out 5050 ms 22740 KB Time limit exceeded
23 Halted 0 ms 0 KB -