#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
unsigned n, m;
vector<unsigned>* adjlist;
unsigned* answer;
void dfs(unsigned index, unsigned prev){
++answer[adjlist[index].size()-1];
for(const unsigned& x : adjlist[index]){
if(x != prev){
dfs(x, index);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
adjlist = new vector<unsigned>[n+m];
for(unsigned i=1; i<n+m; ++i){
unsigned x, y;
cin >> x >> y;
--x;
--y;
adjlist[x].push_back(y);
adjlist[y].push_back(x);
}
answer = new unsigned[n+1];
fill_n(answer,n+1,0);
dfs(adjlist[0].front(),0);
unsigned i=n;
for(; answer[i]==0 && i>1; --i);
for(; i>1; --i){
cout << i << ' ' << answer[i] << '\n';
answer[i-1] += answer[i];
}
delete[] answer;
delete[] adjlist;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
111 ms |
13036 KB |
Output is correct |
4 |
Correct |
127 ms |
14444 KB |
Output is correct |
5 |
Correct |
24 ms |
3188 KB |
Output is correct |
6 |
Correct |
128 ms |
14572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
111 ms |
13036 KB |
Output is correct |
4 |
Correct |
127 ms |
14444 KB |
Output is correct |
5 |
Correct |
24 ms |
3188 KB |
Output is correct |
6 |
Correct |
128 ms |
14572 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
10 ms |
1272 KB |
Output is correct |
27 |
Correct |
121 ms |
14060 KB |
Output is correct |
28 |
Correct |
127 ms |
14444 KB |
Output is correct |
29 |
Correct |
81 ms |
9208 KB |
Output is correct |
30 |
Correct |
98 ms |
12664 KB |
Output is correct |
31 |
Correct |
16 ms |
2552 KB |
Output is correct |
32 |
Correct |
12 ms |
1656 KB |
Output is correct |
33 |
Correct |
117 ms |
11512 KB |
Output is correct |
34 |
Correct |
127 ms |
12664 KB |
Output is correct |
35 |
Correct |
101 ms |
13180 KB |
Output is correct |
36 |
Correct |
144 ms |
12028 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |