Submission #3384765


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n;
	vector<vector<int>> c(100010), edge(n);
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		c[a].push_back(i);
	}
	cin >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		edge[a - 1].push_back(b - 1);
		edge[b - 1].push_back(a - 1);
	}
	vector<int> num(n), adjmax(n);
	for (int i = 0; i < 100010; ++i) {
		if (!c[i].size()) continue;
		bool f = true;
		while (f) {
			for (int a : c[i]) {
				adjmax[a] = max(adjmax[a], num[a] - 1);
				for (int b : edge[a]) {
					adjmax[a] = max(adjmax[a], num[b] - 1);
					adjmax[b] = max(adjmax[b], num[a] - 1);
				}
			}
			f = false;
			for (int a : c[i]) {
				for (int b : edge[a]) {
					if (num[a] < adjmax[b] + 1) {
						f = true;
						num[a] = adjmax[b] + 1;
					}
				}
			}
		}
		for (int a : c[i]) {
			adjmax[a] = max(adjmax[a], num[a]);
			for (int b : edge[a]) {
				adjmax[a] = max(adjmax[a], num[b]);
				adjmax[b] = max(adjmax[b], num[a]);
			}
		}
	}
	long long ans = 0;
	for (int i : num) ans += max(i, 1);
	cout << ans << "\n";
	return 0;
}

Submission Info

Submission Time
Task J - Black Company
User riantkb
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1156 Byte
Status AC
Exec Time 185 ms
Memory 12800 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 62
Set Name Test Cases
All 00_sample_00, 00_sample_01, 00_sample_02, 00_sample_03, 00_sample_04, 10_rand_00, 10_rand_01, 10_rand_02, 10_rand_03, 10_rand_04, 11_max_rand_00, 11_max_rand_01, 11_max_rand_02, 11_max_rand_03, 11_max_rand_04, 20_path_00, 20_path_01, 20_path_02, 20_path_03, 20_path_04, 21_max_path_00, 21_max_path_01, 21_max_path_02, 21_max_path_03, 21_max_path_04, 30_star_00, 30_star_01, 30_star_02, 30_star_03, 30_star_04, 31_max_star_00, 31_max_star_01, 31_max_star_02, 31_max_star_03, 31_max_star_04, 40_clique_00, 40_clique_01, 40_clique_02, 40_clique_03, 40_clique_04, 41_max_clique_00, 41_max_clique_01, 41_max_clique_02, 41_max_clique_03, 41_max_clique_04, 50_discon_00, 50_discon_01, 50_discon_02, 50_discon_03, 50_discon_04, 51_max_discon_00, 51_max_discon_01, 51_max_discon_02, 51_max_discon_03, 51_max_discon_04, 60_noedge_00, 60_noedge_01, 60_noedge_02, 60_noedge_03, 60_noedge_04, 61_max_noedge_00, 61_min_noedge
Case Name Status Exec Time Memory
00_sample_00 AC 2 ms 2560 KB
00_sample_01 AC 2 ms 2560 KB
00_sample_02 AC 2 ms 2560 KB
00_sample_03 AC 2 ms 2560 KB
00_sample_04 AC 3 ms 2560 KB
10_rand_00 AC 62 ms 4224 KB
10_rand_01 AC 162 ms 11136 KB
10_rand_02 AC 90 ms 10752 KB
10_rand_03 AC 36 ms 5888 KB
10_rand_04 AC 21 ms 5120 KB
11_max_rand_00 AC 82 ms 10752 KB
11_max_rand_01 AC 185 ms 12800 KB
11_max_rand_02 AC 49 ms 9088 KB
11_max_rand_03 AC 90 ms 9856 KB
11_max_rand_04 AC 153 ms 9216 KB
20_path_00 AC 2 ms 2560 KB
20_path_01 AC 79 ms 9088 KB
20_path_02 AC 24 ms 4480 KB
20_path_03 AC 39 ms 5504 KB
20_path_04 AC 38 ms 5120 KB
21_max_path_00 AC 115 ms 11904 KB
21_max_path_01 AC 115 ms 11904 KB
21_max_path_02 AC 119 ms 11904 KB
21_max_path_03 AC 119 ms 10880 KB
21_max_path_04 AC 128 ms 9344 KB
30_star_00 AC 62 ms 8060 KB
30_star_01 AC 81 ms 9848 KB
30_star_02 AC 82 ms 9720 KB
30_star_03 AC 7 ms 3200 KB
30_star_04 AC 98 ms 8824 KB
31_max_star_00 AC 108 ms 12408 KB
31_max_star_01 AC 111 ms 12408 KB
31_max_star_02 AC 113 ms 12408 KB
31_max_star_03 AC 115 ms 11256 KB
31_max_star_04 AC 113 ms 9720 KB
40_clique_00 AC 62 ms 4736 KB
40_clique_01 AC 6 ms 2688 KB
40_clique_02 AC 3 ms 2560 KB
40_clique_03 AC 79 ms 4992 KB
40_clique_04 AC 2 ms 2560 KB
41_max_clique_00 AC 91 ms 5248 KB
41_max_clique_01 AC 91 ms 5248 KB
41_max_clique_02 AC 91 ms 5248 KB
41_max_clique_03 AC 91 ms 5248 KB
41_max_clique_04 AC 91 ms 5248 KB
50_discon_00 AC 7 ms 3072 KB
50_discon_01 AC 72 ms 6912 KB
50_discon_02 AC 112 ms 10752 KB
50_discon_03 AC 62 ms 5888 KB
50_discon_04 AC 101 ms 7296 KB
51_max_discon_00 AC 101 ms 11392 KB
51_max_discon_01 AC 94 ms 11520 KB
51_max_discon_02 AC 127 ms 11904 KB
51_max_discon_03 AC 93 ms 9088 KB
51_max_discon_04 AC 124 ms 9216 KB
60_noedge_00 AC 6 ms 3328 KB
60_noedge_01 AC 24 ms 6272 KB
60_noedge_02 AC 14 ms 4608 KB
60_noedge_03 AC 39 ms 7296 KB
60_noedge_04 AC 15 ms 4864 KB
61_max_noedge_00 AC 44 ms 8832 KB
61_min_noedge AC 2 ms 2560 KB