版本比较
LCA 笔记
正文
增加 13 行删除 13 行
90 行未改动919293949595969798997 行未改动10710810911011111111211311411554 行未改动17017117217317417417517617717814 行未改动1931941951961971971981992002018 行未改动21021121221321421421521621721884 行未改动3033043053063073073083093103117 行未改动31932032132232332332432532632785 行未改动4134144154164174174184194204218 行未改动430431432433434434435436437438120 行未改动全部展开55956056156256356356456556656756856856957057157216 行未改动5895905915925935935945955965978 行未改动60660760860961061061161290 行未改动
signed main(){ ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> s;
int x,y; for(int i = 1; i < n; i++){7 行未改动 cin >> x >> y; cout << lca(x,y) << endl; } return 0;} }```::::
---54 行未改动}
inline void dfs2(int x,int t){ top[x] = t,id[x] = ++cnt;
if(!wson[x]) return;
dfs2(wson[x],t);
14 行未改动
signed main(){ ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> s;
int x,y; for(int i = 1; i < n; i++){8 行未改动 cin >> x >> y; cout << lca(x,y) << endl; } return 0;} }```::::
---84 行未改动
signed main(){ ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> s;
int x,y; for(int i = 1; i < n; i++){7 行未改动 cin >> x >> y; cout << lca(x,y) << endl; } return 0;} }```::::
---85 行未改动
signed main(){ ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> s;
int x,y; for(int i = 1; i < n; i++){8 行未改动 if(x == y) cout << x << endl; else cout << lca(x,y) << endl; } return 0;} }```::::
---120 行未改动全部展开
inline void dfs(int x,int father){ dep[x] = dep[father] + 1; fa[x] = father;
int p = lb[father],q = lb[p]; if(dep[father] - dep[p] != dep[p] - dep[q]) lb[x] = father; else lb[x] = q;
for(int i = pre[x]; i; i=e[i].ne){ int y = e[i].to; if(y != father) dfs(y,x); }16 行未改动
signed main(){ ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> s;
int x,y; for(int i = 1; i < n; i++){8 行未改动 if(x == y) cout << x << endl; else cout << lca(x,y) << endl; } return 0;} }```::::