# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
540136 |
2022-03-19T11:05:41 Z |
PixelCat |
Mergers (JOI19_mergers) |
C++14 |
|
1622 ms |
147860 KB |
/* code by the cute ~~Dengdualang~~ PixelCat owo */
/* as cute as nacho neko (aka. my wife)! */
/* Nhade stay for a night here */
/* 183234 deng deng deng pixelcat oops */
/* (yang wang yesu)*2 */
/* ^ some weird stuff. nvm =w= */
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#define int LL //__int128
#define double long double
using namespace std;
using LL = long long;
using LLL = __int128_t;
using uLL = unsigned long long;
using pii = pair<int, int>;
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define L(id) (id * 2 + 1)
#define R(id) (id * 2 + 2)
#define LO(x) (x & (-x))
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (int)(998244353)
// #define MOD (int)((LL)1e9 + 7)
#define INF (int)(4e18) // 9e18
#define EPS (1e-6)
#ifdef NYAOWO
#include "library/debug.hpp"
inline void USACO(const string &s) {
cerr << "USACO: " << s << "\n";
}
#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
inline void NYA() {
ios::sync_with_stdio(false);
cin.tie(0);
}
inline int gcd(int a, int b) {
return __gcd(a, b);
}
inline int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int fpow(int b, int p, const int &mod) {
int ans = 1;
while (p) {
if (p & 1) ans = ans * b % mod;
p >>= 1;
b = b * b % mod;
}
return ans;
}
int fpow(int b, int p) {
return fpow(b, p, MOD);
}
template <typename T>
inline void chmin(T &_a, const T &_b) {
if (_b < _a) _a = _b;
}
template <typename T>
inline void chmax(T &_a, const T &_b) {
if (_b > _a) _a = _b;
}
// mt19937_64 rng(
// chrono::steady_clock::now().time_since_epoch().count());
vector<int> adj[500050];
int s[500050];
int tot[500050];
struct OWO{
int oao;
map<int,int> cnt;
OWO(): oao(0), cnt(){}
void add(int k,int x){
if(cnt.count(k)) oao-=(cnt[k]!=tot[k]);
cnt[k]+=x;
oao+=(cnt[k]!=tot[k]);
}
bool check(){
return oao==0;
}
};
void merge(OWO &a,OWO &b){
if(sz(a.cnt)<sz(b.cnt)){
swap(a.oao,b.oao);
swap(a.cnt,b.cnt);
}
for(auto &p:b.cnt){
a.add(p.F,p.S);
}
}
int thonk[500050];
void dfs(int n,int p,OWO &owo){
owo.add(s[n],1);
for(auto &i:adj[n]) if(i!=p){
OWO o2;
dfs(i,n,o2);
merge(owo,o2);
}
if(owo.check()) thonk[n]=1;
// debug(n,p);
// debug(owo.oao);
// debug(owo.cnt);
}
int nowid=0;
int id[500050];
int deg[500050];
void build(int n,int p){
if(thonk[n]){
nowid++;
id[n]=nowid;
if(n!=p){
deg[id[n]]++;
deg[id[p]]++;
}
}
else id[n]=id[p];
for(auto &i:adj[n]) if(i!=p) build(i,n);
}
int32_t main() {
NYA();
// nyaacho >/////<
// miku sama bless me >/////<
int n,m; cin>>n>>m;
For(i,1,n-1){
int a,b; cin>>a>>b;
adj[a].eb(b);
adj[b].eb(a);
}
For(i,1,n){
cin>>s[i];
tot[s[i]]++;
}
OWO owo;
dfs(1,1,owo);
build(1,1);
int ans=0;
For(i,1,nowid) ans+=(deg[i]==1);
cout<<(ans+1)/2<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11992 KB |
Output is correct |
2 |
Correct |
9 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
11992 KB |
Output is correct |
4 |
Correct |
8 ms |
12072 KB |
Output is correct |
5 |
Correct |
8 ms |
11992 KB |
Output is correct |
6 |
Correct |
7 ms |
11992 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
8 ms |
12056 KB |
Output is correct |
9 |
Correct |
8 ms |
11992 KB |
Output is correct |
10 |
Correct |
7 ms |
11992 KB |
Output is correct |
11 |
Correct |
8 ms |
12072 KB |
Output is correct |
12 |
Correct |
7 ms |
11992 KB |
Output is correct |
13 |
Correct |
7 ms |
12076 KB |
Output is correct |
14 |
Correct |
8 ms |
12076 KB |
Output is correct |
15 |
Correct |
8 ms |
12076 KB |
Output is correct |
16 |
Correct |
7 ms |
11992 KB |
Output is correct |
17 |
Correct |
11 ms |
12128 KB |
Output is correct |
18 |
Correct |
8 ms |
12004 KB |
Output is correct |
19 |
Correct |
7 ms |
12004 KB |
Output is correct |
20 |
Correct |
8 ms |
12004 KB |
Output is correct |
21 |
Correct |
7 ms |
12088 KB |
Output is correct |
22 |
Correct |
7 ms |
12084 KB |
Output is correct |
23 |
Correct |
8 ms |
12088 KB |
Output is correct |
24 |
Correct |
8 ms |
12004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11992 KB |
Output is correct |
2 |
Correct |
9 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
11992 KB |
Output is correct |
4 |
Correct |
8 ms |
12072 KB |
Output is correct |
5 |
Correct |
8 ms |
11992 KB |
Output is correct |
6 |
Correct |
7 ms |
11992 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
8 ms |
12056 KB |
Output is correct |
9 |
Correct |
8 ms |
11992 KB |
Output is correct |
10 |
Correct |
7 ms |
11992 KB |
Output is correct |
11 |
Correct |
8 ms |
12072 KB |
Output is correct |
12 |
Correct |
7 ms |
11992 KB |
Output is correct |
13 |
Correct |
7 ms |
12076 KB |
Output is correct |
14 |
Correct |
8 ms |
12076 KB |
Output is correct |
15 |
Correct |
8 ms |
12076 KB |
Output is correct |
16 |
Correct |
7 ms |
11992 KB |
Output is correct |
17 |
Correct |
11 ms |
12128 KB |
Output is correct |
18 |
Correct |
8 ms |
12004 KB |
Output is correct |
19 |
Correct |
7 ms |
12004 KB |
Output is correct |
20 |
Correct |
8 ms |
12004 KB |
Output is correct |
21 |
Correct |
7 ms |
12088 KB |
Output is correct |
22 |
Correct |
7 ms |
12084 KB |
Output is correct |
23 |
Correct |
8 ms |
12088 KB |
Output is correct |
24 |
Correct |
8 ms |
12004 KB |
Output is correct |
25 |
Correct |
8 ms |
12004 KB |
Output is correct |
26 |
Correct |
10 ms |
12388 KB |
Output is correct |
27 |
Correct |
10 ms |
12328 KB |
Output is correct |
28 |
Correct |
10 ms |
12768 KB |
Output is correct |
29 |
Correct |
12 ms |
12528 KB |
Output is correct |
30 |
Correct |
11 ms |
12244 KB |
Output is correct |
31 |
Correct |
7 ms |
12116 KB |
Output is correct |
32 |
Correct |
10 ms |
12860 KB |
Output is correct |
33 |
Correct |
8 ms |
12072 KB |
Output is correct |
34 |
Correct |
9 ms |
12412 KB |
Output is correct |
35 |
Correct |
11 ms |
12480 KB |
Output is correct |
36 |
Correct |
9 ms |
12252 KB |
Output is correct |
37 |
Correct |
10 ms |
12348 KB |
Output is correct |
38 |
Correct |
8 ms |
12076 KB |
Output is correct |
39 |
Correct |
11 ms |
12508 KB |
Output is correct |
40 |
Correct |
9 ms |
12300 KB |
Output is correct |
41 |
Correct |
8 ms |
12252 KB |
Output is correct |
42 |
Correct |
11 ms |
12416 KB |
Output is correct |
43 |
Correct |
9 ms |
12900 KB |
Output is correct |
44 |
Correct |
8 ms |
12132 KB |
Output is correct |
45 |
Correct |
11 ms |
12608 KB |
Output is correct |
46 |
Correct |
14 ms |
12412 KB |
Output is correct |
47 |
Correct |
8 ms |
12004 KB |
Output is correct |
48 |
Correct |
10 ms |
12280 KB |
Output is correct |
49 |
Correct |
9 ms |
12500 KB |
Output is correct |
50 |
Correct |
10 ms |
12756 KB |
Output is correct |
51 |
Correct |
10 ms |
12340 KB |
Output is correct |
52 |
Correct |
9 ms |
12220 KB |
Output is correct |
53 |
Correct |
10 ms |
12372 KB |
Output is correct |
54 |
Correct |
10 ms |
12208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11992 KB |
Output is correct |
2 |
Correct |
9 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
11992 KB |
Output is correct |
4 |
Correct |
8 ms |
12072 KB |
Output is correct |
5 |
Correct |
8 ms |
11992 KB |
Output is correct |
6 |
Correct |
7 ms |
11992 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
8 ms |
12056 KB |
Output is correct |
9 |
Correct |
8 ms |
11992 KB |
Output is correct |
10 |
Correct |
7 ms |
11992 KB |
Output is correct |
11 |
Correct |
8 ms |
12072 KB |
Output is correct |
12 |
Correct |
7 ms |
11992 KB |
Output is correct |
13 |
Correct |
7 ms |
12076 KB |
Output is correct |
14 |
Correct |
8 ms |
12076 KB |
Output is correct |
15 |
Correct |
8 ms |
12076 KB |
Output is correct |
16 |
Correct |
7 ms |
11992 KB |
Output is correct |
17 |
Correct |
11 ms |
12128 KB |
Output is correct |
18 |
Correct |
8 ms |
12004 KB |
Output is correct |
19 |
Correct |
7 ms |
12004 KB |
Output is correct |
20 |
Correct |
8 ms |
12004 KB |
Output is correct |
21 |
Correct |
7 ms |
12088 KB |
Output is correct |
22 |
Correct |
7 ms |
12084 KB |
Output is correct |
23 |
Correct |
8 ms |
12088 KB |
Output is correct |
24 |
Correct |
8 ms |
12004 KB |
Output is correct |
25 |
Correct |
7 ms |
12000 KB |
Output is correct |
26 |
Correct |
51 ms |
19020 KB |
Output is correct |
27 |
Correct |
108 ms |
18888 KB |
Output is correct |
28 |
Correct |
9 ms |
12260 KB |
Output is correct |
29 |
Correct |
10 ms |
12072 KB |
Output is correct |
30 |
Correct |
8 ms |
12116 KB |
Output is correct |
31 |
Correct |
81 ms |
19028 KB |
Output is correct |
32 |
Correct |
8 ms |
12244 KB |
Output is correct |
33 |
Correct |
100 ms |
38488 KB |
Output is correct |
34 |
Correct |
86 ms |
18780 KB |
Output is correct |
35 |
Correct |
9 ms |
12388 KB |
Output is correct |
36 |
Correct |
79 ms |
20844 KB |
Output is correct |
37 |
Correct |
9 ms |
12284 KB |
Output is correct |
38 |
Correct |
9 ms |
12256 KB |
Output is correct |
39 |
Correct |
61 ms |
18956 KB |
Output is correct |
40 |
Correct |
9 ms |
12900 KB |
Output is correct |
41 |
Correct |
74 ms |
18688 KB |
Output is correct |
42 |
Correct |
94 ms |
25088 KB |
Output is correct |
43 |
Correct |
7 ms |
12000 KB |
Output is correct |
44 |
Correct |
94 ms |
39340 KB |
Output is correct |
45 |
Correct |
95 ms |
31576 KB |
Output is correct |
46 |
Correct |
10 ms |
12244 KB |
Output is correct |
47 |
Correct |
11 ms |
12216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
19020 KB |
Output is correct |
2 |
Correct |
123 ms |
27908 KB |
Output is correct |
3 |
Correct |
10 ms |
12372 KB |
Output is correct |
4 |
Correct |
9 ms |
12280 KB |
Output is correct |
5 |
Correct |
8 ms |
12116 KB |
Output is correct |
6 |
Correct |
7 ms |
12116 KB |
Output is correct |
7 |
Correct |
8 ms |
12244 KB |
Output is correct |
8 |
Correct |
144 ms |
23872 KB |
Output is correct |
9 |
Correct |
9 ms |
12212 KB |
Output is correct |
10 |
Correct |
91 ms |
19800 KB |
Output is correct |
11 |
Correct |
8 ms |
12116 KB |
Output is correct |
12 |
Correct |
73 ms |
19248 KB |
Output is correct |
13 |
Correct |
155 ms |
24080 KB |
Output is correct |
14 |
Correct |
202 ms |
29388 KB |
Output is correct |
15 |
Correct |
53 ms |
18948 KB |
Output is correct |
16 |
Correct |
9 ms |
12372 KB |
Output is correct |
17 |
Correct |
8 ms |
12108 KB |
Output is correct |
18 |
Correct |
117 ms |
27080 KB |
Output is correct |
19 |
Correct |
155 ms |
38168 KB |
Output is correct |
20 |
Correct |
10 ms |
12420 KB |
Output is correct |
21 |
Correct |
9 ms |
12076 KB |
Output is correct |
22 |
Correct |
106 ms |
23748 KB |
Output is correct |
23 |
Correct |
10 ms |
12328 KB |
Output is correct |
24 |
Correct |
87 ms |
20432 KB |
Output is correct |
25 |
Correct |
145 ms |
35556 KB |
Output is correct |
26 |
Correct |
9 ms |
12472 KB |
Output is correct |
27 |
Correct |
11 ms |
12708 KB |
Output is correct |
28 |
Correct |
10 ms |
12344 KB |
Output is correct |
29 |
Correct |
9 ms |
12212 KB |
Output is correct |
30 |
Correct |
9 ms |
12372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11992 KB |
Output is correct |
2 |
Correct |
9 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
11992 KB |
Output is correct |
4 |
Correct |
8 ms |
12072 KB |
Output is correct |
5 |
Correct |
8 ms |
11992 KB |
Output is correct |
6 |
Correct |
7 ms |
11992 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
8 ms |
12056 KB |
Output is correct |
9 |
Correct |
8 ms |
11992 KB |
Output is correct |
10 |
Correct |
7 ms |
11992 KB |
Output is correct |
11 |
Correct |
8 ms |
12072 KB |
Output is correct |
12 |
Correct |
7 ms |
11992 KB |
Output is correct |
13 |
Correct |
7 ms |
12076 KB |
Output is correct |
14 |
Correct |
8 ms |
12076 KB |
Output is correct |
15 |
Correct |
8 ms |
12076 KB |
Output is correct |
16 |
Correct |
7 ms |
11992 KB |
Output is correct |
17 |
Correct |
11 ms |
12128 KB |
Output is correct |
18 |
Correct |
8 ms |
12004 KB |
Output is correct |
19 |
Correct |
7 ms |
12004 KB |
Output is correct |
20 |
Correct |
8 ms |
12004 KB |
Output is correct |
21 |
Correct |
7 ms |
12088 KB |
Output is correct |
22 |
Correct |
7 ms |
12084 KB |
Output is correct |
23 |
Correct |
8 ms |
12088 KB |
Output is correct |
24 |
Correct |
8 ms |
12004 KB |
Output is correct |
25 |
Correct |
8 ms |
12004 KB |
Output is correct |
26 |
Correct |
10 ms |
12388 KB |
Output is correct |
27 |
Correct |
10 ms |
12328 KB |
Output is correct |
28 |
Correct |
10 ms |
12768 KB |
Output is correct |
29 |
Correct |
12 ms |
12528 KB |
Output is correct |
30 |
Correct |
11 ms |
12244 KB |
Output is correct |
31 |
Correct |
7 ms |
12116 KB |
Output is correct |
32 |
Correct |
10 ms |
12860 KB |
Output is correct |
33 |
Correct |
8 ms |
12072 KB |
Output is correct |
34 |
Correct |
9 ms |
12412 KB |
Output is correct |
35 |
Correct |
11 ms |
12480 KB |
Output is correct |
36 |
Correct |
9 ms |
12252 KB |
Output is correct |
37 |
Correct |
10 ms |
12348 KB |
Output is correct |
38 |
Correct |
8 ms |
12076 KB |
Output is correct |
39 |
Correct |
11 ms |
12508 KB |
Output is correct |
40 |
Correct |
9 ms |
12300 KB |
Output is correct |
41 |
Correct |
8 ms |
12252 KB |
Output is correct |
42 |
Correct |
11 ms |
12416 KB |
Output is correct |
43 |
Correct |
9 ms |
12900 KB |
Output is correct |
44 |
Correct |
8 ms |
12132 KB |
Output is correct |
45 |
Correct |
11 ms |
12608 KB |
Output is correct |
46 |
Correct |
14 ms |
12412 KB |
Output is correct |
47 |
Correct |
8 ms |
12004 KB |
Output is correct |
48 |
Correct |
10 ms |
12280 KB |
Output is correct |
49 |
Correct |
9 ms |
12500 KB |
Output is correct |
50 |
Correct |
10 ms |
12756 KB |
Output is correct |
51 |
Correct |
10 ms |
12340 KB |
Output is correct |
52 |
Correct |
9 ms |
12220 KB |
Output is correct |
53 |
Correct |
10 ms |
12372 KB |
Output is correct |
54 |
Correct |
10 ms |
12208 KB |
Output is correct |
55 |
Correct |
7 ms |
12000 KB |
Output is correct |
56 |
Correct |
51 ms |
19020 KB |
Output is correct |
57 |
Correct |
108 ms |
18888 KB |
Output is correct |
58 |
Correct |
9 ms |
12260 KB |
Output is correct |
59 |
Correct |
10 ms |
12072 KB |
Output is correct |
60 |
Correct |
8 ms |
12116 KB |
Output is correct |
61 |
Correct |
81 ms |
19028 KB |
Output is correct |
62 |
Correct |
8 ms |
12244 KB |
Output is correct |
63 |
Correct |
100 ms |
38488 KB |
Output is correct |
64 |
Correct |
86 ms |
18780 KB |
Output is correct |
65 |
Correct |
9 ms |
12388 KB |
Output is correct |
66 |
Correct |
79 ms |
20844 KB |
Output is correct |
67 |
Correct |
9 ms |
12284 KB |
Output is correct |
68 |
Correct |
9 ms |
12256 KB |
Output is correct |
69 |
Correct |
61 ms |
18956 KB |
Output is correct |
70 |
Correct |
9 ms |
12900 KB |
Output is correct |
71 |
Correct |
74 ms |
18688 KB |
Output is correct |
72 |
Correct |
94 ms |
25088 KB |
Output is correct |
73 |
Correct |
7 ms |
12000 KB |
Output is correct |
74 |
Correct |
94 ms |
39340 KB |
Output is correct |
75 |
Correct |
95 ms |
31576 KB |
Output is correct |
76 |
Correct |
10 ms |
12244 KB |
Output is correct |
77 |
Correct |
11 ms |
12216 KB |
Output is correct |
78 |
Correct |
50 ms |
19020 KB |
Output is correct |
79 |
Correct |
123 ms |
27908 KB |
Output is correct |
80 |
Correct |
10 ms |
12372 KB |
Output is correct |
81 |
Correct |
9 ms |
12280 KB |
Output is correct |
82 |
Correct |
8 ms |
12116 KB |
Output is correct |
83 |
Correct |
7 ms |
12116 KB |
Output is correct |
84 |
Correct |
8 ms |
12244 KB |
Output is correct |
85 |
Correct |
144 ms |
23872 KB |
Output is correct |
86 |
Correct |
9 ms |
12212 KB |
Output is correct |
87 |
Correct |
91 ms |
19800 KB |
Output is correct |
88 |
Correct |
8 ms |
12116 KB |
Output is correct |
89 |
Correct |
73 ms |
19248 KB |
Output is correct |
90 |
Correct |
155 ms |
24080 KB |
Output is correct |
91 |
Correct |
202 ms |
29388 KB |
Output is correct |
92 |
Correct |
53 ms |
18948 KB |
Output is correct |
93 |
Correct |
9 ms |
12372 KB |
Output is correct |
94 |
Correct |
8 ms |
12108 KB |
Output is correct |
95 |
Correct |
117 ms |
27080 KB |
Output is correct |
96 |
Correct |
155 ms |
38168 KB |
Output is correct |
97 |
Correct |
10 ms |
12420 KB |
Output is correct |
98 |
Correct |
9 ms |
12076 KB |
Output is correct |
99 |
Correct |
106 ms |
23748 KB |
Output is correct |
100 |
Correct |
10 ms |
12328 KB |
Output is correct |
101 |
Correct |
87 ms |
20432 KB |
Output is correct |
102 |
Correct |
145 ms |
35556 KB |
Output is correct |
103 |
Correct |
9 ms |
12472 KB |
Output is correct |
104 |
Correct |
11 ms |
12708 KB |
Output is correct |
105 |
Correct |
10 ms |
12344 KB |
Output is correct |
106 |
Correct |
9 ms |
12212 KB |
Output is correct |
107 |
Correct |
9 ms |
12372 KB |
Output is correct |
108 |
Correct |
714 ms |
67676 KB |
Output is correct |
109 |
Correct |
677 ms |
95028 KB |
Output is correct |
110 |
Correct |
707 ms |
126500 KB |
Output is correct |
111 |
Correct |
1212 ms |
147860 KB |
Output is correct |
112 |
Correct |
1212 ms |
129404 KB |
Output is correct |
113 |
Correct |
891 ms |
88240 KB |
Output is correct |
114 |
Correct |
524 ms |
46148 KB |
Output is correct |
115 |
Correct |
520 ms |
46136 KB |
Output is correct |
116 |
Correct |
969 ms |
59680 KB |
Output is correct |
117 |
Correct |
1622 ms |
95664 KB |
Output is correct |
118 |
Correct |
538 ms |
48620 KB |
Output is correct |
119 |
Correct |
1387 ms |
94524 KB |
Output is correct |
120 |
Correct |
1203 ms |
131660 KB |
Output is correct |
121 |
Correct |
1368 ms |
92832 KB |
Output is correct |
122 |
Correct |
1420 ms |
76760 KB |
Output is correct |
123 |
Correct |
917 ms |
92544 KB |
Output is correct |
124 |
Correct |
1323 ms |
89140 KB |
Output is correct |