# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
894922 |
2023-12-29T08:40:45 Z |
vjudge1 |
Mergers (JOI19_mergers) |
C++17 |
|
61 ms |
53700 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);
if(n == 1) return cout << 0 , 0;
if(ok[1]) ans++;
cout << ans/2 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
41564 KB |
Output is correct |
2 |
Correct |
8 ms |
41564 KB |
Output is correct |
3 |
Correct |
10 ms |
41564 KB |
Output is correct |
4 |
Correct |
8 ms |
41564 KB |
Output is correct |
5 |
Correct |
8 ms |
41656 KB |
Output is correct |
6 |
Correct |
8 ms |
41600 KB |
Output is correct |
7 |
Correct |
9 ms |
41560 KB |
Output is correct |
8 |
Correct |
8 ms |
41560 KB |
Output is correct |
9 |
Correct |
8 ms |
41564 KB |
Output is correct |
10 |
Correct |
8 ms |
41636 KB |
Output is correct |
11 |
Correct |
8 ms |
41564 KB |
Output is correct |
12 |
Correct |
8 ms |
41560 KB |
Output is correct |
13 |
Correct |
8 ms |
41600 KB |
Output is correct |
14 |
Correct |
8 ms |
41564 KB |
Output is correct |
15 |
Correct |
8 ms |
41656 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 |
41564 KB |
Output is correct |
2 |
Correct |
8 ms |
41564 KB |
Output is correct |
3 |
Correct |
10 ms |
41564 KB |
Output is correct |
4 |
Correct |
8 ms |
41564 KB |
Output is correct |
5 |
Correct |
8 ms |
41656 KB |
Output is correct |
6 |
Correct |
8 ms |
41600 KB |
Output is correct |
7 |
Correct |
9 ms |
41560 KB |
Output is correct |
8 |
Correct |
8 ms |
41560 KB |
Output is correct |
9 |
Correct |
8 ms |
41564 KB |
Output is correct |
10 |
Correct |
8 ms |
41636 KB |
Output is correct |
11 |
Correct |
8 ms |
41564 KB |
Output is correct |
12 |
Correct |
8 ms |
41560 KB |
Output is correct |
13 |
Correct |
8 ms |
41600 KB |
Output is correct |
14 |
Correct |
8 ms |
41564 KB |
Output is correct |
15 |
Correct |
8 ms |
41656 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 |
41564 KB |
Output is correct |
2 |
Correct |
8 ms |
41564 KB |
Output is correct |
3 |
Correct |
10 ms |
41564 KB |
Output is correct |
4 |
Correct |
8 ms |
41564 KB |
Output is correct |
5 |
Correct |
8 ms |
41656 KB |
Output is correct |
6 |
Correct |
8 ms |
41600 KB |
Output is correct |
7 |
Correct |
9 ms |
41560 KB |
Output is correct |
8 |
Correct |
8 ms |
41560 KB |
Output is correct |
9 |
Correct |
8 ms |
41564 KB |
Output is correct |
10 |
Correct |
8 ms |
41636 KB |
Output is correct |
11 |
Correct |
8 ms |
41564 KB |
Output is correct |
12 |
Correct |
8 ms |
41560 KB |
Output is correct |
13 |
Correct |
8 ms |
41600 KB |
Output is correct |
14 |
Correct |
8 ms |
41564 KB |
Output is correct |
15 |
Correct |
8 ms |
41656 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 |
61 ms |
53700 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 |
41564 KB |
Output is correct |
2 |
Correct |
8 ms |
41564 KB |
Output is correct |
3 |
Correct |
10 ms |
41564 KB |
Output is correct |
4 |
Correct |
8 ms |
41564 KB |
Output is correct |
5 |
Correct |
8 ms |
41656 KB |
Output is correct |
6 |
Correct |
8 ms |
41600 KB |
Output is correct |
7 |
Correct |
9 ms |
41560 KB |
Output is correct |
8 |
Correct |
8 ms |
41560 KB |
Output is correct |
9 |
Correct |
8 ms |
41564 KB |
Output is correct |
10 |
Correct |
8 ms |
41636 KB |
Output is correct |
11 |
Correct |
8 ms |
41564 KB |
Output is correct |
12 |
Correct |
8 ms |
41560 KB |
Output is correct |
13 |
Correct |
8 ms |
41600 KB |
Output is correct |
14 |
Correct |
8 ms |
41564 KB |
Output is correct |
15 |
Correct |
8 ms |
41656 KB |
Output is correct |
16 |
Incorrect |
8 ms |
41564 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |