답안 #293057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293057 2020-09-07T15:52:06 Z 임성재(#5807) 서류 전달 (ROI16_sending) C++17
0 / 100
117 ms 12412 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace 
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef unsigned int ui;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n, q;
int p[200010];
int d[200010];
vector<int> g[200010];
ui v[40000010];
int cnt;

int main() {
	fast;

	cin >> n >> q;

	for(int i=2; i<=n; i++) {
		cin >> p[i];
		d[i] = d[p[i]] + 1;
	}

	for(int i=1; i<=q; i++) {
		int u, v;
		cin >> u >> v;

		while(u != v) {
			if(d[u] > d[v]) swap(u, v);
			g[v].eb(i);
			v = p[v];
		}
	}

	for(int i=2; i<=n; i++) {
		sort(all(g[i]));

		//assert(g[i].size() <= 30);

		for(int j=0; j<g[i].size(); j++) {
			for(int k=j+1; k<g[i].size(); k++) {
				//v[cnt++] = g[i][j] + (ui) q * g[i][k];
				//cnt++;
			}
		}
	}

	sort(v, v + cnt);

	int ans = 0;
	ui mxi = 1 + 2 * q;
	
	for(int i=0; i<cnt; ) {
		int j = i;
		while(j < cnt && v[i] == v[j]) j++;

		if(j - i > ans) {
			ans = j - i;
			mxi = v[i];
		}

		i = j;
	}
	
	cout << ans << "\n";
	cout << (mxi-1) % q + 1 << " " << (mxi-1) / q;
}

Compilation message

sending.cpp: In function 'int main()':
sending.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int j=0; j<g[i].size(); j++) {
      |                ~^~~~~~~~~~~~
sending.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |    for(int k=j+1; k<g[i].size(); k++) {
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 117 ms 12412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 8824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -