Cod sursa(job #2924226)

Utilizator AlexandruBenescuAlexandru Benescu AlexandruBenescu Data 27 septembrie 2022 16:39:55
Problema Arbore Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>
#define L 100005
using namespace std;
ifstream fin("arbore.in");
ofstream fout("arbore.out");

vector <int> G[L];
int lin_tree[L], pos_in_lin_tree[L], sons[L], i1 = 1, n, q;
bool vis[L];

void DFS(int node){
  vis[node] = true;
  pos_in_lin_tree[node] = i1;
  lin_tree[i1++] = node;
  sons[node] = 1;
  for (auto it : G[node])
    if (!vis[it]){
      DFS(it);
      sons[node] += sons[it];
    }
}

int main(){
  int i, a, b, root = 1;
  fin >> n >> q;
  for (i = 1; i < n; i++){
    fin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  DFS(root);
  /**
  for (i = 1; i <= n; i++)
    cout << lin_tree[i] << " ";
  cout << "\n";
  for (i = 1; i <= n; i++)
    cout << pos_in_lin_tree[i] << " ";
  cout << "\n";
  for (i = 1; i <= n; i++)
    cout << sons[i] << " ";
  cout << "\n";
  **/
  return 0;
}