#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5+10;
const int MN = 2e5+5;
vector<int> adj[MAXN];
int diff[MAXN],tree[MAXN];
void upd(int p, int x){
while(p <= MN){
tree[p] += x;
p += p&(-p);
//cout << p << "\n";
}
}
int query(int p){
int ret = 0;
while(p > 0){
ret += tree[p];
p -= p&(-p);
}
return ret;
}
void dfs(int u, int p){
for(auto v : adj[u]){
if(v != p){
dfs(v,u);
}
}
int num = adj[u].size()-1;
//cout << u << " " << num << "\n";
if(num >= 2){
upd(2,1);
upd(num+1,-1);
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N,M; cin >> N >> M; //1 to N are leaves
for(int i = 1;i<=N+M-1;++i){
int u,v; cin >> u >> v;
adj[u].push_back(v); adj[v].push_back(u);
}
dfs(N+1,0);
for(int i = 2;i<=MN;++i){
int q = query(i);
if(q != 0){
cout << i << " " << q << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
53 ms |
15340 KB |
Output is correct |
4 |
Correct |
63 ms |
16320 KB |
Output is correct |
5 |
Correct |
15 ms |
7384 KB |
Output is correct |
6 |
Correct |
71 ms |
16324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
3 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Correct |
4 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
4 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4952 KB |
Output is correct |
2 |
Correct |
4 ms |
5208 KB |
Output is correct |
3 |
Correct |
4 ms |
5208 KB |
Output is correct |
4 |
Correct |
3 ms |
5164 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
5 ms |
5212 KB |
Output is correct |
8 |
Correct |
4 ms |
4956 KB |
Output is correct |
9 |
Correct |
4 ms |
5212 KB |
Output is correct |
10 |
Correct |
4 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
4952 KB |
Output is correct |
3 |
Correct |
53 ms |
15340 KB |
Output is correct |
4 |
Correct |
63 ms |
16320 KB |
Output is correct |
5 |
Correct |
15 ms |
7384 KB |
Output is correct |
6 |
Correct |
71 ms |
16324 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
4 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
4956 KB |
Output is correct |
12 |
Correct |
4 ms |
4956 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
4 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
4 ms |
4952 KB |
Output is correct |
17 |
Correct |
4 ms |
5208 KB |
Output is correct |
18 |
Correct |
4 ms |
5208 KB |
Output is correct |
19 |
Correct |
3 ms |
5164 KB |
Output is correct |
20 |
Correct |
3 ms |
4956 KB |
Output is correct |
21 |
Correct |
3 ms |
5212 KB |
Output is correct |
22 |
Correct |
5 ms |
5212 KB |
Output is correct |
23 |
Correct |
4 ms |
4956 KB |
Output is correct |
24 |
Correct |
4 ms |
5212 KB |
Output is correct |
25 |
Correct |
4 ms |
5212 KB |
Output is correct |
26 |
Correct |
7 ms |
5724 KB |
Output is correct |
27 |
Correct |
58 ms |
15992 KB |
Output is correct |
28 |
Correct |
59 ms |
16412 KB |
Output is correct |
29 |
Correct |
37 ms |
12612 KB |
Output is correct |
30 |
Correct |
38 ms |
14684 KB |
Output is correct |
31 |
Correct |
9 ms |
6748 KB |
Output is correct |
32 |
Correct |
7 ms |
6232 KB |
Output is correct |
33 |
Correct |
46 ms |
13648 KB |
Output is correct |
34 |
Correct |
55 ms |
17936 KB |
Output is correct |
35 |
Correct |
41 ms |
15048 KB |
Output is correct |
36 |
Correct |
57 ms |
14164 KB |
Output is correct |
37 |
Correct |
3 ms |
4956 KB |
Output is correct |