Submission #3384748


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
 
int main() {
    int n, m;
    cin >> n;
    vector<vector<int>> c(100010);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        c[a].push_back(i);
    }
    cin >> m;
    vector<vector<int>> edge(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> num(n);
    vector<int> 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 1616 Byte
Status AC
Exec Time 197 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 3 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 2 ms 2560 KB
10_rand_00 AC 64 ms 4224 KB
10_rand_01 AC 164 ms 11136 KB
10_rand_02 AC 93 ms 10752 KB
10_rand_03 AC 37 ms 5888 KB
10_rand_04 AC 21 ms 5120 KB
11_max_rand_00 AC 81 ms 10752 KB
11_max_rand_01 AC 197 ms 12800 KB
11_max_rand_02 AC 50 ms 9088 KB
11_max_rand_03 AC 90 ms 9856 KB
11_max_rand_04 AC 154 ms 9216 KB
20_path_00 AC 3 ms 2560 KB
20_path_01 AC 80 ms 9088 KB
20_path_02 AC 24 ms 4480 KB
20_path_03 AC 40 ms 5504 KB
20_path_04 AC 38 ms 5120 KB
21_max_path_00 AC 118 ms 11904 KB
21_max_path_01 AC 117 ms 11904 KB
21_max_path_02 AC 120 ms 11904 KB
21_max_path_03 AC 120 ms 10880 KB
21_max_path_04 AC 117 ms 9344 KB
30_star_00 AC 64 ms 8060 KB
30_star_01 AC 88 ms 9848 KB
30_star_02 AC 86 ms 9720 KB
30_star_03 AC 9 ms 3200 KB
30_star_04 AC 97 ms 8824 KB
31_max_star_00 AC 109 ms 12408 KB
31_max_star_01 AC 112 ms 12408 KB
31_max_star_02 AC 120 ms 12408 KB
31_max_star_03 AC 119 ms 11256 KB
31_max_star_04 AC 114 ms 9720 KB
40_clique_00 AC 63 ms 4736 KB
40_clique_01 AC 6 ms 2688 KB
40_clique_02 AC 3 ms 2560 KB
40_clique_03 AC 80 ms 4992 KB
40_clique_04 AC 2 ms 2560 KB
41_max_clique_00 AC 92 ms 5248 KB
41_max_clique_01 AC 92 ms 5248 KB
41_max_clique_02 AC 92 ms 5248 KB
41_max_clique_03 AC 94 ms 5248 KB
41_max_clique_04 AC 92 ms 5248 KB
50_discon_00 AC 8 ms 3072 KB
50_discon_01 AC 73 ms 6912 KB
50_discon_02 AC 112 ms 10752 KB
50_discon_03 AC 63 ms 5888 KB
50_discon_04 AC 102 ms 7296 KB
51_max_discon_00 AC 102 ms 11392 KB
51_max_discon_01 AC 96 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 131 ms 9216 KB
60_noedge_00 AC 7 ms 3328 KB
60_noedge_01 AC 26 ms 6272 KB
60_noedge_02 AC 15 ms 4736 KB
60_noedge_03 AC 41 ms 7296 KB
60_noedge_04 AC 16 ms 4864 KB
61_max_noedge_00 AC 45 ms 8832 KB
61_min_noedge AC 2 ms 2560 KB