Submission #110825

# Submission time Handle Problem Language Result Execution time Memory
110825 2019-05-12T10:31:03 Z IOrtroiii Mergers (JOI19_mergers) C++14
100 / 100
1137 ms 69624 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 500500;

int n, m;
int a[N];
pair<int, int> e[N];
vector< pair<int, int> > g[N];
bool br[N];
int num[N], low[N], tt;

void dfs(int u,int p) {
   num[u] = low[u] = ++tt;
   for (auto nx : g[u]) {
      int v, id; tie(v, id) = nx;
      if (!num[v]) {
         dfs(v, id);
         low[u] = min(low[u], low[v]);
         if (low[v] > num[u]) br[id] = true;
      } else if (id != p) low[u] = min(low[u], num[v]);
   }
}

int cnt;
int comp[N];
int deg[N];

void dfs2(int u) {
   comp[u] = cnt;
   for (auto nx : g[u]) {
      int v, id; tie(v, id) = nx;
      if (!br[id] && !comp[v]) {
         dfs2(v);
      }
   }
}

int main() {
   scanf("%d %d", &n, &m);
   for (int i = 1; i < n; ++i) {
      int u, v; scanf("%d %d", &u, &v);
      e[i] = {u, v};
   }
   for (int i = 1; i <= n; ++i) scanf("%d", a + i);
   for (int i = 1; i < n; ++i) {
      int u, v; tie(u, v) = e[i];
      u = a[u], v = a[v];
      if (u == v) continue;
      g[u].push_back({v, i});
      g[v].push_back({u, i});
   }

   dfs(1, -1);
   for (int i = 1; i <= m; ++i) {
      if (!comp[i]) {
         ++cnt;
         dfs2(i);
      }
   }
   for (int i = 1; i <= n; ++i) {
      for (auto nx : g[i]) {
         int v, id; tie(v, id) = nx;
         if (br[id]) ++deg[comp[v]];
      }
   }
   printf("%d\n", (count(deg + 1, deg + cnt + 1, 1) + 1) / 2);
}

Compilation message

mergers.cpp: In function 'int main()':
mergers.cpp:68:61: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::iterator_traits<int*>::difference_type {aka long int}' [-Wformat=]
    printf("%d\n", (count(deg + 1, deg + cnt + 1, 1) + 1) / 2);
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
mergers.cpp:41:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &n, &m);
    ~~~~~^~~~~~~~~~~~~~~~~
mergers.cpp:43:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       int u, v; scanf("%d %d", &u, &v);
                 ~~~~~^~~~~~~~~~~~~~~~~
mergers.cpp:46:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
                                 ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 13 ms 12160 KB Output is correct
3 Correct 14 ms 12160 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Correct 15 ms 12160 KB Output is correct
6 Correct 14 ms 12160 KB Output is correct
7 Correct 14 ms 12160 KB Output is correct
8 Correct 16 ms 12160 KB Output is correct
9 Correct 14 ms 12132 KB Output is correct
10 Correct 14 ms 12160 KB Output is correct
11 Correct 13 ms 12076 KB Output is correct
12 Correct 13 ms 12160 KB Output is correct
13 Correct 14 ms 12160 KB Output is correct
14 Correct 13 ms 12160 KB Output is correct
15 Correct 14 ms 12160 KB Output is correct
16 Correct 15 ms 12160 KB Output is correct
17 Correct 12 ms 12160 KB Output is correct
18 Correct 12 ms 12160 KB Output is correct
19 Correct 16 ms 12160 KB Output is correct
20 Correct 15 ms 12160 KB Output is correct
21 Correct 13 ms 12160 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 15 ms 12160 KB Output is correct
24 Correct 13 ms 12160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 13 ms 12160 KB Output is correct
3 Correct 14 ms 12160 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Correct 15 ms 12160 KB Output is correct
6 Correct 14 ms 12160 KB Output is correct
7 Correct 14 ms 12160 KB Output is correct
8 Correct 16 ms 12160 KB Output is correct
9 Correct 14 ms 12132 KB Output is correct
10 Correct 14 ms 12160 KB Output is correct
11 Correct 13 ms 12076 KB Output is correct
12 Correct 13 ms 12160 KB Output is correct
13 Correct 14 ms 12160 KB Output is correct
14 Correct 13 ms 12160 KB Output is correct
15 Correct 14 ms 12160 KB Output is correct
16 Correct 15 ms 12160 KB Output is correct
17 Correct 12 ms 12160 KB Output is correct
18 Correct 12 ms 12160 KB Output is correct
19 Correct 16 ms 12160 KB Output is correct
20 Correct 15 ms 12160 KB Output is correct
21 Correct 13 ms 12160 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 15 ms 12160 KB Output is correct
24 Correct 13 ms 12160 KB Output is correct
25 Correct 17 ms 12160 KB Output is correct
26 Correct 18 ms 12288 KB Output is correct
27 Correct 15 ms 12152 KB Output is correct
28 Correct 15 ms 12416 KB Output is correct
29 Correct 16 ms 12508 KB Output is correct
30 Correct 14 ms 12288 KB Output is correct
31 Correct 15 ms 12160 KB Output is correct
32 Correct 17 ms 12416 KB Output is correct
33 Correct 17 ms 12160 KB Output is correct
34 Correct 15 ms 12288 KB Output is correct
35 Correct 15 ms 12544 KB Output is correct
36 Correct 14 ms 12160 KB Output is correct
37 Correct 17 ms 12288 KB Output is correct
38 Correct 14 ms 12160 KB Output is correct
39 Correct 15 ms 12416 KB Output is correct
40 Correct 14 ms 12160 KB Output is correct
41 Correct 14 ms 12160 KB Output is correct
42 Correct 16 ms 12288 KB Output is correct
43 Correct 15 ms 12164 KB Output is correct
44 Correct 13 ms 12160 KB Output is correct
45 Correct 15 ms 12416 KB Output is correct
46 Correct 18 ms 12288 KB Output is correct
47 Correct 13 ms 12160 KB Output is correct
48 Correct 16 ms 12288 KB Output is correct
49 Correct 15 ms 12408 KB Output is correct
50 Correct 15 ms 12416 KB Output is correct
51 Correct 14 ms 12280 KB Output is correct
52 Correct 16 ms 12288 KB Output is correct
53 Correct 15 ms 12288 KB Output is correct
54 Correct 16 ms 12288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 13 ms 12160 KB Output is correct
3 Correct 14 ms 12160 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Correct 15 ms 12160 KB Output is correct
6 Correct 14 ms 12160 KB Output is correct
7 Correct 14 ms 12160 KB Output is correct
8 Correct 16 ms 12160 KB Output is correct
9 Correct 14 ms 12132 KB Output is correct
10 Correct 14 ms 12160 KB Output is correct
11 Correct 13 ms 12076 KB Output is correct
12 Correct 13 ms 12160 KB Output is correct
13 Correct 14 ms 12160 KB Output is correct
14 Correct 13 ms 12160 KB Output is correct
15 Correct 14 ms 12160 KB Output is correct
16 Correct 15 ms 12160 KB Output is correct
17 Correct 12 ms 12160 KB Output is correct
18 Correct 12 ms 12160 KB Output is correct
19 Correct 16 ms 12160 KB Output is correct
20 Correct 15 ms 12160 KB Output is correct
21 Correct 13 ms 12160 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 15 ms 12160 KB Output is correct
24 Correct 13 ms 12160 KB Output is correct
25 Correct 15 ms 12160 KB Output is correct
26 Correct 53 ms 16496 KB Output is correct
27 Correct 61 ms 16760 KB Output is correct
28 Correct 17 ms 12160 KB Output is correct
29 Correct 14 ms 12160 KB Output is correct
30 Correct 18 ms 12152 KB Output is correct
31 Correct 49 ms 14840 KB Output is correct
32 Correct 13 ms 12288 KB Output is correct
33 Correct 55 ms 16468 KB Output is correct
34 Correct 51 ms 16504 KB Output is correct
35 Correct 13 ms 12160 KB Output is correct
36 Correct 43 ms 14840 KB Output is correct
37 Correct 13 ms 12160 KB Output is correct
38 Correct 14 ms 12160 KB Output is correct
39 Correct 46 ms 16488 KB Output is correct
40 Correct 14 ms 12160 KB Output is correct
41 Correct 43 ms 14712 KB Output is correct
42 Correct 48 ms 16504 KB Output is correct
43 Correct 13 ms 12160 KB Output is correct
44 Correct 46 ms 14712 KB Output is correct
45 Correct 48 ms 16504 KB Output is correct
46 Correct 15 ms 12288 KB Output is correct
47 Correct 14 ms 12260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 16596 KB Output is correct
2 Correct 84 ms 20688 KB Output is correct
3 Correct 14 ms 12288 KB Output is correct
4 Correct 14 ms 12160 KB Output is correct
5 Correct 14 ms 12160 KB Output is correct
6 Correct 14 ms 12160 KB Output is correct
7 Correct 15 ms 12288 KB Output is correct
8 Correct 103 ms 18824 KB Output is correct
9 Correct 15 ms 12160 KB Output is correct
10 Correct 51 ms 14968 KB Output is correct
11 Correct 14 ms 12160 KB Output is correct
12 Correct 53 ms 15000 KB Output is correct
13 Correct 80 ms 18552 KB Output is correct
14 Correct 150 ms 20472 KB Output is correct
15 Correct 52 ms 16488 KB Output is correct
16 Correct 15 ms 12288 KB Output is correct
17 Correct 13 ms 12160 KB Output is correct
18 Correct 105 ms 20188 KB Output is correct
19 Correct 140 ms 25592 KB Output is correct
20 Correct 16 ms 12288 KB Output is correct
21 Correct 16 ms 12160 KB Output is correct
22 Correct 71 ms 18284 KB Output is correct
23 Correct 15 ms 12288 KB Output is correct
24 Correct 54 ms 15608 KB Output is correct
25 Correct 130 ms 23160 KB Output is correct
26 Correct 15 ms 12416 KB Output is correct
27 Correct 15 ms 12416 KB Output is correct
28 Correct 15 ms 12288 KB Output is correct
29 Correct 18 ms 12288 KB Output is correct
30 Correct 14 ms 12288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 13 ms 12160 KB Output is correct
3 Correct 14 ms 12160 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Correct 15 ms 12160 KB Output is correct
6 Correct 14 ms 12160 KB Output is correct
7 Correct 14 ms 12160 KB Output is correct
8 Correct 16 ms 12160 KB Output is correct
9 Correct 14 ms 12132 KB Output is correct
10 Correct 14 ms 12160 KB Output is correct
11 Correct 13 ms 12076 KB Output is correct
12 Correct 13 ms 12160 KB Output is correct
13 Correct 14 ms 12160 KB Output is correct
14 Correct 13 ms 12160 KB Output is correct
15 Correct 14 ms 12160 KB Output is correct
16 Correct 15 ms 12160 KB Output is correct
17 Correct 12 ms 12160 KB Output is correct
18 Correct 12 ms 12160 KB Output is correct
19 Correct 16 ms 12160 KB Output is correct
20 Correct 15 ms 12160 KB Output is correct
21 Correct 13 ms 12160 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 15 ms 12160 KB Output is correct
24 Correct 13 ms 12160 KB Output is correct
25 Correct 17 ms 12160 KB Output is correct
26 Correct 18 ms 12288 KB Output is correct
27 Correct 15 ms 12152 KB Output is correct
28 Correct 15 ms 12416 KB Output is correct
29 Correct 16 ms 12508 KB Output is correct
30 Correct 14 ms 12288 KB Output is correct
31 Correct 15 ms 12160 KB Output is correct
32 Correct 17 ms 12416 KB Output is correct
33 Correct 17 ms 12160 KB Output is correct
34 Correct 15 ms 12288 KB Output is correct
35 Correct 15 ms 12544 KB Output is correct
36 Correct 14 ms 12160 KB Output is correct
37 Correct 17 ms 12288 KB Output is correct
38 Correct 14 ms 12160 KB Output is correct
39 Correct 15 ms 12416 KB Output is correct
40 Correct 14 ms 12160 KB Output is correct
41 Correct 14 ms 12160 KB Output is correct
42 Correct 16 ms 12288 KB Output is correct
43 Correct 15 ms 12164 KB Output is correct
44 Correct 13 ms 12160 KB Output is correct
45 Correct 15 ms 12416 KB Output is correct
46 Correct 18 ms 12288 KB Output is correct
47 Correct 13 ms 12160 KB Output is correct
48 Correct 16 ms 12288 KB Output is correct
49 Correct 15 ms 12408 KB Output is correct
50 Correct 15 ms 12416 KB Output is correct
51 Correct 14 ms 12280 KB Output is correct
52 Correct 16 ms 12288 KB Output is correct
53 Correct 15 ms 12288 KB Output is correct
54 Correct 16 ms 12288 KB Output is correct
55 Correct 15 ms 12160 KB Output is correct
56 Correct 53 ms 16496 KB Output is correct
57 Correct 61 ms 16760 KB Output is correct
58 Correct 17 ms 12160 KB Output is correct
59 Correct 14 ms 12160 KB Output is correct
60 Correct 18 ms 12152 KB Output is correct
61 Correct 49 ms 14840 KB Output is correct
62 Correct 13 ms 12288 KB Output is correct
63 Correct 55 ms 16468 KB Output is correct
64 Correct 51 ms 16504 KB Output is correct
65 Correct 13 ms 12160 KB Output is correct
66 Correct 43 ms 14840 KB Output is correct
67 Correct 13 ms 12160 KB Output is correct
68 Correct 14 ms 12160 KB Output is correct
69 Correct 46 ms 16488 KB Output is correct
70 Correct 14 ms 12160 KB Output is correct
71 Correct 43 ms 14712 KB Output is correct
72 Correct 48 ms 16504 KB Output is correct
73 Correct 13 ms 12160 KB Output is correct
74 Correct 46 ms 14712 KB Output is correct
75 Correct 48 ms 16504 KB Output is correct
76 Correct 15 ms 12288 KB Output is correct
77 Correct 14 ms 12260 KB Output is correct
78 Correct 55 ms 16596 KB Output is correct
79 Correct 84 ms 20688 KB Output is correct
80 Correct 14 ms 12288 KB Output is correct
81 Correct 14 ms 12160 KB Output is correct
82 Correct 14 ms 12160 KB Output is correct
83 Correct 14 ms 12160 KB Output is correct
84 Correct 15 ms 12288 KB Output is correct
85 Correct 103 ms 18824 KB Output is correct
86 Correct 15 ms 12160 KB Output is correct
87 Correct 51 ms 14968 KB Output is correct
88 Correct 14 ms 12160 KB Output is correct
89 Correct 53 ms 15000 KB Output is correct
90 Correct 80 ms 18552 KB Output is correct
91 Correct 150 ms 20472 KB Output is correct
92 Correct 52 ms 16488 KB Output is correct
93 Correct 15 ms 12288 KB Output is correct
94 Correct 13 ms 12160 KB Output is correct
95 Correct 105 ms 20188 KB Output is correct
96 Correct 140 ms 25592 KB Output is correct
97 Correct 16 ms 12288 KB Output is correct
98 Correct 16 ms 12160 KB Output is correct
99 Correct 71 ms 18284 KB Output is correct
100 Correct 15 ms 12288 KB Output is correct
101 Correct 54 ms 15608 KB Output is correct
102 Correct 130 ms 23160 KB Output is correct
103 Correct 15 ms 12416 KB Output is correct
104 Correct 15 ms 12416 KB Output is correct
105 Correct 15 ms 12288 KB Output is correct
106 Correct 18 ms 12288 KB Output is correct
107 Correct 14 ms 12288 KB Output is correct
108 Correct 544 ms 43664 KB Output is correct
109 Correct 192 ms 25628 KB Output is correct
110 Correct 194 ms 25616 KB Output is correct
111 Correct 1089 ms 69624 KB Output is correct
112 Correct 1068 ms 67236 KB Output is correct
113 Correct 527 ms 53572 KB Output is correct
114 Correct 181 ms 25600 KB Output is correct
115 Correct 193 ms 25564 KB Output is correct
116 Correct 550 ms 43256 KB Output is correct
117 Correct 1083 ms 54968 KB Output is correct
118 Correct 199 ms 26716 KB Output is correct
119 Correct 943 ms 55004 KB Output is correct
120 Correct 1137 ms 66472 KB Output is correct
121 Correct 1083 ms 55200 KB Output is correct
122 Correct 830 ms 55512 KB Output is correct
123 Correct 594 ms 56028 KB Output is correct
124 Correct 1114 ms 50808 KB Output is correct