# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
894920 |
2023-12-29T08:23:58 Z |
vjudge1 |
Mergers (JOI19_mergers) |
C++17 |
|
57 ms |
53828 KB |
//In His Name
#include <bits/stdc++.h>
//#pragma GCC optimization("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
using namespace std;
#define ll long long
#define int ll
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define bug(x) cout << "Ah shit , here we go again : " << x <<endl
#define all(x) x.begin() , x.end()
const int maxn = 5e5 + 10, MOD = 1e9 + 7;
const ll INF = 1e18;
int n , k , state[maxn] , a[maxn] , ans , ok[maxn];
vector<int> adj[maxn];
map<int,int> gooni[maxn];
void Dfs(int v , int p){
for(int u : adj[v]) {
if (u == p) continue;
Dfs(u, v);
if (gooni[v].size() < gooni[u].size()) swap(gooni[v], gooni[u]) , swap(ok[v] , ok[u]);
}
for(int u : adj[v]){
if(u == p) continue;
ok[v] += ok[u];
for(auto i : gooni[u]){
gooni[v][i.F] += i.S;
if(gooni[v][i.F] == state[i.F]) gooni[v].erase(i.F);
}
}
gooni[v][a[v]]++;
if(gooni[v][a[v]] == state[a[v]]) gooni[v].erase(a[v]);
if(gooni[v].size() == 0 and v != 1){
if(!ok[v]) ans ++;
ok[v] = 1;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin >> n >> k;
for(int i = 1 ; i < n ; i++){
int u , v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
for(int i = 1 ; i <= n ; i++){
cin >> a[i];
state[a[i]]++;
}
Dfs(1 , 0);
cout << (ans+1)/2 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
41560 KB |
Output is correct |
2 |
Correct |
9 ms |
41560 KB |
Output is correct |
3 |
Correct |
9 ms |
41564 KB |
Output is correct |
4 |
Correct |
8 ms |
41664 KB |
Output is correct |
5 |
Correct |
8 ms |
41564 KB |
Output is correct |
6 |
Correct |
8 ms |
41564 KB |
Output is correct |
7 |
Correct |
8 ms |
41676 KB |
Output is correct |
8 |
Correct |
8 ms |
41564 KB |
Output is correct |
9 |
Correct |
9 ms |
41564 KB |
Output is correct |
10 |
Correct |
8 ms |
41660 KB |
Output is correct |
11 |
Correct |
8 ms |
41688 KB |
Output is correct |
12 |
Correct |
8 ms |
41564 KB |
Output is correct |
13 |
Correct |
8 ms |
41564 KB |
Output is correct |
14 |
Correct |
8 ms |
41564 KB |
Output is correct |
15 |
Correct |
8 ms |
41564 KB |
Output is correct |
16 |
Incorrect |
8 ms |
41564 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
41560 KB |
Output is correct |
2 |
Correct |
9 ms |
41560 KB |
Output is correct |
3 |
Correct |
9 ms |
41564 KB |
Output is correct |
4 |
Correct |
8 ms |
41664 KB |
Output is correct |
5 |
Correct |
8 ms |
41564 KB |
Output is correct |
6 |
Correct |
8 ms |
41564 KB |
Output is correct |
7 |
Correct |
8 ms |
41676 KB |
Output is correct |
8 |
Correct |
8 ms |
41564 KB |
Output is correct |
9 |
Correct |
9 ms |
41564 KB |
Output is correct |
10 |
Correct |
8 ms |
41660 KB |
Output is correct |
11 |
Correct |
8 ms |
41688 KB |
Output is correct |
12 |
Correct |
8 ms |
41564 KB |
Output is correct |
13 |
Correct |
8 ms |
41564 KB |
Output is correct |
14 |
Correct |
8 ms |
41564 KB |
Output is correct |
15 |
Correct |
8 ms |
41564 KB |
Output is correct |
16 |
Incorrect |
8 ms |
41564 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
41560 KB |
Output is correct |
2 |
Correct |
9 ms |
41560 KB |
Output is correct |
3 |
Correct |
9 ms |
41564 KB |
Output is correct |
4 |
Correct |
8 ms |
41664 KB |
Output is correct |
5 |
Correct |
8 ms |
41564 KB |
Output is correct |
6 |
Correct |
8 ms |
41564 KB |
Output is correct |
7 |
Correct |
8 ms |
41676 KB |
Output is correct |
8 |
Correct |
8 ms |
41564 KB |
Output is correct |
9 |
Correct |
9 ms |
41564 KB |
Output is correct |
10 |
Correct |
8 ms |
41660 KB |
Output is correct |
11 |
Correct |
8 ms |
41688 KB |
Output is correct |
12 |
Correct |
8 ms |
41564 KB |
Output is correct |
13 |
Correct |
8 ms |
41564 KB |
Output is correct |
14 |
Correct |
8 ms |
41564 KB |
Output is correct |
15 |
Correct |
8 ms |
41564 KB |
Output is correct |
16 |
Incorrect |
8 ms |
41564 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
53828 KB |
Output is correct |
2 |
Incorrect |
45 ms |
49604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
41560 KB |
Output is correct |
2 |
Correct |
9 ms |
41560 KB |
Output is correct |
3 |
Correct |
9 ms |
41564 KB |
Output is correct |
4 |
Correct |
8 ms |
41664 KB |
Output is correct |
5 |
Correct |
8 ms |
41564 KB |
Output is correct |
6 |
Correct |
8 ms |
41564 KB |
Output is correct |
7 |
Correct |
8 ms |
41676 KB |
Output is correct |
8 |
Correct |
8 ms |
41564 KB |
Output is correct |
9 |
Correct |
9 ms |
41564 KB |
Output is correct |
10 |
Correct |
8 ms |
41660 KB |
Output is correct |
11 |
Correct |
8 ms |
41688 KB |
Output is correct |
12 |
Correct |
8 ms |
41564 KB |
Output is correct |
13 |
Correct |
8 ms |
41564 KB |
Output is correct |
14 |
Correct |
8 ms |
41564 KB |
Output is correct |
15 |
Correct |
8 ms |
41564 KB |
Output is correct |
16 |
Incorrect |
8 ms |
41564 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |