(C++) - 백준(BOJ) 1761번 : 정점들의 거리 답
Lowest Common Ancestor(LCA)문제입니다 //트리상에서의 최단거리는 두 정점 사이의 거리이다. #include #include #include #include using namespace std; int n, m, u, v,cost,ans; int c[40001],depth[40001],dist[40001],parent[40001]; struct Edge { int to; int cost; Edge(int to, int cost) : to(to), cost(cost) {}; }; vector a[40001];//간선의 정점간의 가중치를 저장 queue q;//큐 생성 int lca(int u, int v) { if (depth[u] < depth[v]) swap(u, v); while ..