This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |