#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define X first
#define Y second
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
os<<"{";
for(It it=bg;it!=ed;it++) {
os<<(it==bg?"":",")<<*it;
}
os<<"}";
return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif
const int MAXN = 2003;
const ll MOD = 1000000007;
int n, color[MAXN], m;
vector<int> edge[MAXN];
int dep[MAXN], cnt[MAXN];
bool app[MAXN];
void dfs (int nd, int par, int d) {
dep[d] = color[nd];
cnt[d]++;
for (auto v : edge[nd]) {
if (v != par) {
dfs(v, nd, d+1);
}
}
}
void solve (int nd) {
memset(cnt, 0, sizeof(cnt));
memset(app, 0, sizeof(app));
dfs(nd, -1, 0);
for (int i=1; i<=n; i++) {
if (cnt[i] == 1) {
app[dep[i]] = true;
}
}
int cnt = 0;
for (int i=1; i<=m; i++) {
if (app[i]) {
cnt++;
}
}
cout << cnt << endl;
}
/*********************GoodLuck***********************/
int main () {
IOS();
cin >> n >> m;
REP (i, n-1) {
int u, v;
cin >> u >> v;
edge[u].eb(v);
edge[v].eb(u);
}
REP1 (i, n) {
cin >> color[i];
}
REP1 (i, n) {
solve(i);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
59 ms |
540 KB |
Output is correct |
3 |
Correct |
24 ms |
504 KB |
Output is correct |
4 |
Correct |
70 ms |
760 KB |
Output is correct |
5 |
Correct |
72 ms |
504 KB |
Output is correct |
6 |
Correct |
94 ms |
636 KB |
Output is correct |
7 |
Correct |
83 ms |
508 KB |
Output is correct |
8 |
Correct |
64 ms |
504 KB |
Output is correct |
9 |
Correct |
75 ms |
544 KB |
Output is correct |
10 |
Correct |
68 ms |
632 KB |
Output is correct |
11 |
Correct |
69 ms |
504 KB |
Output is correct |
12 |
Correct |
39 ms |
504 KB |
Output is correct |
13 |
Correct |
94 ms |
504 KB |
Output is correct |
14 |
Correct |
71 ms |
760 KB |
Output is correct |
15 |
Correct |
73 ms |
504 KB |
Output is correct |
16 |
Correct |
31 ms |
504 KB |
Output is correct |
17 |
Correct |
72 ms |
504 KB |
Output is correct |
18 |
Correct |
75 ms |
504 KB |
Output is correct |
19 |
Correct |
68 ms |
548 KB |
Output is correct |
20 |
Correct |
97 ms |
640 KB |
Output is correct |
21 |
Correct |
86 ms |
632 KB |
Output is correct |
22 |
Correct |
66 ms |
504 KB |
Output is correct |
23 |
Correct |
73 ms |
504 KB |
Output is correct |
24 |
Correct |
69 ms |
504 KB |
Output is correct |
25 |
Correct |
73 ms |
504 KB |
Output is correct |
26 |
Correct |
43 ms |
504 KB |
Output is correct |
27 |
Correct |
93 ms |
632 KB |
Output is correct |
28 |
Correct |
74 ms |
632 KB |
Output is correct |
29 |
Correct |
78 ms |
504 KB |
Output is correct |
30 |
Correct |
34 ms |
504 KB |
Output is correct |
31 |
Correct |
73 ms |
620 KB |
Output is correct |
32 |
Correct |
80 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
59 ms |
540 KB |
Output is correct |
3 |
Correct |
24 ms |
504 KB |
Output is correct |
4 |
Correct |
70 ms |
760 KB |
Output is correct |
5 |
Correct |
72 ms |
504 KB |
Output is correct |
6 |
Correct |
94 ms |
636 KB |
Output is correct |
7 |
Correct |
83 ms |
508 KB |
Output is correct |
8 |
Correct |
64 ms |
504 KB |
Output is correct |
9 |
Correct |
75 ms |
544 KB |
Output is correct |
10 |
Correct |
68 ms |
632 KB |
Output is correct |
11 |
Correct |
69 ms |
504 KB |
Output is correct |
12 |
Correct |
39 ms |
504 KB |
Output is correct |
13 |
Correct |
94 ms |
504 KB |
Output is correct |
14 |
Correct |
71 ms |
760 KB |
Output is correct |
15 |
Correct |
73 ms |
504 KB |
Output is correct |
16 |
Correct |
31 ms |
504 KB |
Output is correct |
17 |
Correct |
72 ms |
504 KB |
Output is correct |
18 |
Correct |
75 ms |
504 KB |
Output is correct |
19 |
Correct |
68 ms |
548 KB |
Output is correct |
20 |
Correct |
97 ms |
640 KB |
Output is correct |
21 |
Correct |
86 ms |
632 KB |
Output is correct |
22 |
Correct |
66 ms |
504 KB |
Output is correct |
23 |
Correct |
73 ms |
504 KB |
Output is correct |
24 |
Correct |
69 ms |
504 KB |
Output is correct |
25 |
Correct |
73 ms |
504 KB |
Output is correct |
26 |
Correct |
43 ms |
504 KB |
Output is correct |
27 |
Correct |
93 ms |
632 KB |
Output is correct |
28 |
Correct |
74 ms |
632 KB |
Output is correct |
29 |
Correct |
78 ms |
504 KB |
Output is correct |
30 |
Correct |
34 ms |
504 KB |
Output is correct |
31 |
Correct |
73 ms |
620 KB |
Output is correct |
32 |
Correct |
80 ms |
504 KB |
Output is correct |
33 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
34 |
Halted |
0 ms |
0 KB |
- |