将 domjudge 服务从当前服务器迁移到另一台服务器。(docker-compose文件参考另一篇文章:http://blog.zymusic.top/post/36 )
shdocker-compose down
# 在项目根目录的上一级执行
tar -czvf domjudge_backup.tar.gz ./dom #
把压缩包传给你的另一台机器。
shtar -xzvf domjudge_backup.tar.gz
cd dom
# 给数据库目录正确的权限
sudo chown -R 999:999 database/
sudo chmod -R 755 database/
# 给 DomServer 数据目录正确的权限
sudo chown -R 1000:1000 domserver_data/
sudo chmod -R 755 domserver_data/
docker-compose up -d
这样就可以直接启动了(注意docker-compose里面的镜像版本建议我的一致)
在桌面随便新建一个文件夹,命名为英文(我这里命名为 cpp)

点击左上角File,勾选 Auto Save
(在 vscode 设置 Auto Save开启自动保存,一定要开,不然每次写完代码都需要手动 ctrl+s保存)
打开你刚才新建的空文件夹 cpp


bat@echo off for %%i in (a b c d e f g h i j k l m) do ( mkdir "%%i" cd.>"%%i\%%i.cpp" cd.>"%%i\%%i.in" cd.>"%%i\%%i.out" cd.>"%%i\tm%%i.cpp" )
bat@echo off g++ -o main %1\%1.cpp main < %1\%1.in > %1\%1.out type %1\%1.out

在桌面右键,打开终端

切换到 cpp目录,执行 init.bat
cd cpp .\init.bat

cpp#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
cout << s << endl;
return 0;
}

把输入数据放到 a.in中,就可以运行了(前提是配置了g++环境变量,赛场上的机房默认会配好,不用自己下载,如果在自己本地电脑上,就需要先下载g++并配置环境变量,如果你还没有配置,请去网上自行寻找配置方案)
.\run.bat a

.\run.bat a 表示执行run.bat 脚本,a表示参数,这条命令相当于在运行a/a.cpp文件,输入数据是a/a.in,输出数据在文件a/a.out中。
如果你想运行 b/b.cpp,只需要改成.\run.bat b (前提是已经编写好了代码和输入数据)。
但是每次运行一个文件都需要输入.\run.bat a 吗?不需要,在终端输入键盘上下左右键的上键可以弹出上一条命令,这样就不用每次都输入一遍命令了。
但是我们依然无法使用调试功能,只能自己手动打印调试了。不过这种方案相比于使用devcpp还是更方便,而且正式赛场上不一定有你想要的 ide,但是命令行编译是万能的,而且运行的效率肯定比依赖插件要快。
如果还有问题,可以私聊我:3051863421(qq)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 永无BUG */ /* // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = /O // ____/`---'\____ // . ' \\| |// `. // / \\||| : |||// \ // / _||||| -:- |||||- \ // | | \\\ - /// | | // | \_| ''\---/'' | | // \ .-\__ `-` ___/-. / // ___`. .' /--.--\ `. . __ // ."" '< `.___\_<|>_/___.' >'"". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `-. \_ __\ /__ _/ .-` / / // ======`-.____`-.___\_____/___.-`____.-'====== // `=---=' // // ............................................. // 佛祖保佑 永无BUG // 佛曰: // 写字楼里写字间,写字间里程序员; // 程序人员写程序,又拿程序换酒钱。 // 酒醒只在网上坐,酒醉还来网下眠; // 酒醉酒醒日复日,网上网下年复年。 // 但愿老死电脑间,不愿鞠躬老板前; // 奔驰宝马贵者趣,公交自行程序员。 // 别人笑我忒疯癫,我笑自己命太贱; // 不见满街漂亮妹,哪个归得程序员?
/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 永无BUG */ /* // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = /O // ____/`---'\____ // . ' \\| |// `. // / \\||| : |||// \ // / _||||| -:- |||||- \ // | | \\\ - /// | | // | \_| ''\---/'' | | // \ .-\__ `-` ___/-. / // ___`. .' /--.--\ `. . __ // ."" '< `.___\_<|>_/___.' >'"". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `-. \_ __\ /__ _/ .-` / / // ======`-.____`-.___\_____/___.-`____.-'====== // `=---=' // // ............................................. // 佛祖保佑 永无BUG // 佛曰: // 写字楼里写字间,写字间里程序员; // 程序人员写程序,又拿程序换酒钱。 // 酒醒只在网上坐,酒醉还来网下眠; // 酒醉酒醒日复日,网上网下年复年。 // 但愿老死电脑间,不愿鞠躬老板前; // 奔驰宝马贵者趣,公交自行程序员。 // 别人笑我忒疯癫,我笑自己命太贱; // 不见满街漂亮妹,哪个归得程序员? */ /* * _ooOoo_ * o8888888o * 88" . "88 * (| -_- |) * O\ = /O * ___/`---'\____ * . ' \\| |// `. * / \\||| : |||// \ * / _||||| -:- |||||- \ * | | \\\ - /// | | * | \_| ''\---/'' | | * \ .-\__ `-` ___/-. / * ___`. .' /--.--\ `. . __ * ."" '< `.___\_<|>_/___.' >'"". * | | : `- \`.;`\ _ /`;.`/ - ` : | | * \ \ `-. \_ __\ /__ _/ .-` / / * ======`-.____`-.___\_____/___.-`____.-'====== * `=---=' * ............................................. * 佛曰:bug泛滥,我已瘫痪! */ <!-- ´´´´´´´´██´´´´´´´ ´´´´´´´████´´´´´´ ´´´´´████████´´´´ ´´`´███▒▒▒▒███´´´´´ ´´´███▒●▒▒●▒██´´´ ´´´███▒▒▒▒▒▒██´´´´´ ´´´███▒▒▒▒██´ 项目:vue-user-center ´´██████▒▒███´´´´´ 语言: ES6-babel ´██████▒▒▒▒███´´ 框架: vue+vue-router+vuex+iview+axios ██████▒▒▒▒▒▒███´´´´ 构建工具: webpack ´´▓▓▓▓▓▓▓▓▓▓▓▓▓▒´´ 版本控制: git-github ´´▒▒▒▒▓▓▓▓▓▓▓▓▓▒´´´´´ css预处理: less ´.▒▒▒´´▓▓▓▓▓▓▓▓▒´´´´´ 代码风格:eslint-standard ´.▒▒´´´´▓▓▓▓▓▓▓▒ 编辑器: phpstorm ..▒▒.´´´´▓▓▓▓▓▓▓▒ 数据库: mysql ´▒▒▒▒▒▒▒▒▒▒▒▒ 服务器端脚本: php go ´´´´´´´´´███████´´´´´ author: codeRabbit ´´´´´´´´████████´´´´´´´ ´´´´´´´█████████´´´´´´ ´´´´´´██████████´´´´ 大部分人都在关注你飞的高不高,却没人在乎你飞的累不累,这就是现实! ´´´´´´██████████´´´ 我从不相信梦想,我,只,相,信,自,己! ´´´´´´´█████████´´ ´´´´´´´█████████´´´ ´´´´´´´´████████´´´´´ ________▒▒▒▒▒ _________▒▒▒▒ _________▒▒▒▒ ________▒▒_▒▒ _______▒▒__▒▒ _____ ▒▒___▒▒ _____▒▒___▒▒ ____▒▒____▒▒ ___▒▒_____▒▒ ███____ ▒▒ ████____███ █ _███_ _█_███ ——————————————————————————女神保佑,代码无bug—————————————————————— --> /* // .::::. // .::::::::. // ::::::::::: // ..:::::::::::' // '::::::::::::' // .:::::::::: // '::::::::::::::.. // ..::::::::::::. // ``:::::::::::::::: // ::::``:::::::::' .:::. // ::::' ':::::' .::::::::. // .::::' :::: .:::::::'::::. // .:::' ::::: .:::::::::' ':::::. // .::' :::::.:::::::::' ':::::. // .::' ::::::::::::::' ``::::. // ...::: ::::::::::::' ``::. // ````':. ':::::::::' ::::.. // '.:::::' ':'````.. */ <!-- _.._ ,------------. ,' `. (I want you! ) / __) __` \ `-,----------' ( (`-`(-') ) _.-' /) \ = / ( /' |--' . \ ( ,---| `-.)__` )( `-.,--' _`-. '/,' ( Uu", (_ , `/,-' ) `.__, : `-'/ /`--' | `--' | ` `-._ / \ ( /\ . \. / |` \ ,-\ / \| .) / \ ( ,'|\ ,' : | \,`.`--"/ } `,' \ |,' / / "-._ `-/ | "-. "-.,'| ; / _/["---'""] : / |"- ' ' | / ` | --> # # ┏┓ ┏┓ # ┏┛┻━━━┛┻┓ # ┃ ┃ # ┃ ━ ┃ # ┃ ┳┛ ┗┳ ┃ # ┃ ┃ # ┃ ┻ ┃ # ┃ ┃ # ┗━┓ ┏━┛Codes are far away from bugs with the animal protecting # ┃ ┃ 神兽保佑,代码无bug # ┃ ┃ # ┃ ┗━━━┓ # ┃ ┣┓ # ┃ ┏┛ # ┗┓┓┏━┳┓┏┛ # ┃┫┫ ┃┫┫ # ┗┻┛ ┗┻┛ # # ┏┓ ┏┓ # ┏┛┻━━━┛┻┓ # ┃ ┃ # ┃ ━ ┃ # ┃ > <┃ # ┃ ┃ # ┃ . ⌒ ..┃ # ┃ ┃ # ┗━┓ ┏━┛ # ┃ ┃ Codes are far away from bugs with the animal protecting # ┃ ┃ 神兽保佑,代码无bug # ┃ ┃ # ┃ ┃ # ┃ ┃ # ┃ ┃ # ┃ ┗━━━┓ # ┃ ┣┓ # ┃ ┏┛ # ┗┓┓┏━┳┓┏┛ # ┃┫┫ ┃┫┫ # ┗┻┛ ┗┻┛ # ┏┓ ┏┓+ + # ┏┛┻━━━┛┻┓ + + # ┃ ┃ # ┃ ━ ┃ ++ + + + # ████━████ ┃+ # ┃ ┃ + # ┃ ┻ ┃ # ┃ ┃ + + # ┗━┓ ┏━┛ # ┃ ┃ # ┃ ┃ + + + + # ┃ ┃ Codes are far away from bugs with the animal protecting # ┃ ┃ + 神兽保佑,代码无bug # ┃ ┃ # ┃ ┃ + # ┃ ┗━━━┓ + + # ┃ ┣┓ # ┃ ┏┛ # ┗┓┓┏━┳┓┏┛ + + + + # ┃┫┫ ┃┫┫ # ┗┻┛ ┗┻┛+ + + + /*code is far away from bug with the animal protecting * ┏┓ ┏┓ *┏┛┻━━━┛┻┓ *┃ ┃ *┃ ━ ┃ *┃ ┳┛ ┗┳ ┃ *┃ ┃ *┃ ┻ ┃ *┃ ┃ *┗━┓ ┏━┛ * ┃ ┃神兽保佑 * ┃ ┃代码无BUG! * ┃ ┗━━━┓ * ┃ ┣┓ * ┃ ┏┛ * ┗┓┓┏━┳┓┏┛ * ┃┫┫ ┃┫┫ * ┗┻┛ ┗┻┛ * */ # # ┌─┐ ┌─┐ # ┌──┘ ┴───────┘ ┴──┐ # │ │ # │ ─── │ # │ ─┬┘ └┬─ │ # │ │ # │ ─┴─ │ # │ │ # └───┐ ┌───┘ # │ │ # │ │ # │ │ # │ └──────────────┐ # │ │ # │ ├─┐ # │ ┌─┘ # │ │ # └─┐ ┐ ┌───────┬──┐ ┌──┘ # │ ─┤ ─┤ │ ─┤ ─┤ # └──┴──┘ └──┴──┘ # 神兽保佑 # 代码无BUG! # ___====-_ _-====___ # _--^^^#####// \\#####^^^--_ # _-^##########// ( ) \\##########^-_ # -############// |\^^/| \\############- # _/############// (@::@) \\############\_ # /#############(( \\// ))#############\ # -###############\\ (oo) //###############- # -#################\\ / VV \ //#################- # -###################\\/ \//###################- # _#/|##########/\######( /\ )######/\##########|\#_ # |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| # ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' # ` ` ` ` / | | | | \ ' ' ' ' # ( | | | | ) # __\ | | | | /__ # (vvv(VVV)(VVV)vvv) # 神兽保佑 # 代码无BUG! # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # 神兽保佑 # 代码无BUG! # ,----------------, ,---------, # ,-----------------------, ," ,"| # ," ,"| ," ," | # +-----------------------+ | ," ," | # | .-----------------. | | +---------+ | # | | | | | | -==----'| | # | | I LOVE DOS! | | | | | | # | | Bad command or | | |/----|`---= | | # | | C:\>_ | | | ,/|==== ooo | ; # | | | | | // |(((( [33]| ," # | `-----------------' |," .;'| |(((( | ," # +-----------------------+ ;; | | |," # /_)______________(_/ //' | +---------+ # ___________________________/___ `, # / oooooooooooooooo .o. oooo /, \,"----------- # / ==ooooooooooooooo==.o. ooo= // ,`\--{)B ," # /_==__==========__==_ooo__ooo=_/' /___________," # # .-~~~~~~~~~-._ _.-~~~~~~~~~-. # __.' ~. .~ `.__ # .'// \./ \\`. # .'// | \\`. # .'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. \\`. # .'//.-" `-. | .-' "-.\\`. # .'//______.============-.. \ | / ..-============.______\\`. # .'______________________________\|/______________________________`. /**********/**********/**********//**********//**********//**********//**********/ .--, .--, ( ( \.---./ ) ) '.__/o o\__.' {= ^ =} > - < / \ // \\ //| . |\\ "'\ /'"_.-~^`'-. \ _ /--' ` ___)( )(___ (((__) (__))) 高山仰止,景行行止.虽不能至,心向往之。 /**********/**********/**********//**********//**********//**********//**********/ <!-- :: :;J7, :, ::;7: ,ivYi, , ;LLLFS: :iv7Yi :7ri;j5PL ,:ivYLvr ,ivrrirrY2X, :;r@Wwz.7r: :ivu@kexianli. :iL7::,:::iiirii:ii;::::,,irvF7rvvLujL7ur ri::,:,::i:iiiiiii:i:irrv177JX7rYXqZEkvv17 ;i:, , ::::iirrririi:i:::iiir2XXvii;L8OGJr71i :,, ,,: ,::ir@mingyi.irii:i:::j1jri7ZBOS7ivv, ,::, ::rv77iiiriii:iii:i::,rvLq@huhao.Li ,, ,, ,:ir7ir::,:::i;ir:::i:i::rSGGYri712: ::: ,v7r:: ::rrv77:, ,, ,:i7rrii:::::, ir7ri7Lri , 2OBBOi,iiir;r:: ,irriiii::,, ,iv7Luur: ,, i78MBBi,:,:::,:, :7FSL: ,iriii:::i::,,:rLqXv:: : iuMMP: :,:::,:ii;2GY7OBB0viiii:i:iii:i:::iJqL;:: , ::::i ,,,,, ::LuBBu BBBBBErii:i:i:i:i:i:i:r77ii , : , ,,:::rruBZ1MBBqi, :,,,:::,::::::iiriri: , ,,,,::::i: @arqiao. ,:,, ,:::ii;i7: :, rjujLYLi ,,:::::,:::::::::,, ,:i,:,,,,,::i:iii :: BBBBBBBBB0, ,,::: , ,:::::: , ,,,, ,,::::::: i, , ,8BMMBBBBBBi ,,:,, ,,, , , , , , :,::ii::i:: : iZMOMOMBBM2::::::::::,,,, ,,,,,,:,,,::::i:irr:i:::, i ,,:;u0MBMOG1L:::i:::::: ,,,::, ,,, ::::::i:i:iirii:i:i: : ,iuUuuXUkFu7i:iii:i:::, :,:,: ::::::::i:i:::::iirr7iiri:: : :rk@Yizero.i:::::, ,:ii:::::::i:::::i::,::::iirrriiiri::, : 5BMBBBBBBSr:,::rv2kuii:::iii::,:i:,, , ,,:,:i@petermu., , :r50EZ8MBBBBGOBBBZP7::::i::,:::::,: :,:,::i;rrririiii:: :jujYY7LS0ujJL7r::,::i::,::::::::::::::iirirrrrrrr:ii: ,: :@kevensun.:,:,,,::::i:i:::::,,::::::iir;ii;7v77;ii;i, ,,, ,,:,::::::i:iiiii:i::::,, ::::iiiir@xingjief.r;7:i, , , ,,,:,,::::::::iiiiiiiiii:,:,:::::::::iiir;ri7vL77rrirri:: :,, , ::::::::i:::i:::i:i::,,,,,:,::i:i:::iir;@Secbone.ii::: -- /** * ┌───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐ * │Esc│ │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│ ┌┐ ┌┐ ┌┐ * └───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘ └┘ └┘ └┘ * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐ * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │ * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤ * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │ │ * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │ * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter │ │ 4 │ 5 │ 6 │ │ * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤ ┌───┐ ├───┼───┼───┼───┤ * │ Shift │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│ Shift │ │ ↑ │ │ 1 │ 2 │ 3 │ │ * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││ * │ Ctrl│ │Alt │ Space │ Alt│ │ │Ctrl│ │ ← │ ↓ │ → │ │ 0 │ . │←─┘│ * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘ */ /** ************************************************************** * * * .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. * * | ______ | * * | .-" "-. | * * | / \ | * * | _ | | _ | * * | ( \ |, .-. .-. ,| / ) | * * | > "=._ | )(__/ \__)( | _.=" < | * * | (_/"=._"=._ |/ /\ \| _.="_.="\_) | * * | "=._"(_ ^^ _)"_.=" | * * | "=\__|IIIIII|__/=" | * * | _.="| \IIIIII/ |"=._ | * * | _ _.="_.="\ /"=._"=._ _ | * * | ( \_.="_.=" `--------` "=._"=._/ ) | * * | > _.=" "=._ < | * * | (_/ \_) | * * | | * * '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' * * * * LASCIATE OGNI SPERANZA, VOI CH'ENTRATE * ************************************************************** */ /** * 頂頂頂頂頂頂頂頂頂 頂頂頂頂頂頂頂頂頂 * 頂頂頂頂頂頂頂 頂頂 * 頂頂 頂頂頂頂頂頂頂頂頂頂頂 * 頂頂 頂頂頂頂頂頂頂頂頂頂頂 * 頂頂 頂頂 頂頂 * 頂頂 頂頂 頂頂頂 頂頂 * 頂頂 頂頂 頂頂頂 頂頂 * 頂頂 頂頂 頂頂頂 頂頂 * 頂頂 頂頂 頂頂頂 頂頂 * 頂頂 頂頂頂 * 頂頂 頂頂 頂頂 頂頂 * 頂頂頂頂 頂頂頂頂頂 頂頂頂頂頂 * 頂頂頂頂 頂頂頂頂 頂頂頂頂 */ ▄▄▄▄▄ ▀▀▀██████▄▄▄ _______________ ▄▄▄▄▄ █████████▄ / \ ▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Gotta go fast! | ▀▀█████▄▄ ▀██████▄██ | _________________/ ▀▄▄▄▄▄ ▀▀█▄▀█════█▀ |/ ▀▀▀▄ ▀▀███ ▀ ▄▄ ▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌ ______________________________ ██▀▄▄▄██▀▄███▀ ▀▀████ ▄██ █ \\ ▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███ ▌▄▄▀▀▀▀█_____________________________ // ▌ ▐▀████▐███▒▒▒▒▒▐██▌ ▀▄▄▄▄▀ ▀▀████▒▒▒▒▄██▀ ▀▀█████████▀ ▄▄██▀██████▀█ ▄██▀ ▀▀▀ █ ▄█ ▐▌ ▄▄▄▄█▌ ▀█▄▄▄▄▀▀▄ ▌ ▐ ▀▀▄▄▄▀ ▀▀▄▄▀ ██ \ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ \- ▌ SanicCRUD-vue ▀ ▀ - ▌ (o) ▀ /- ▌ Go Go Go ! ▀ ▀ / ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀ ██ # d*##$. # zP"""""$e. $" $o #4$ '$ $" $ #'$ '$ J$ $F # 'b $k $> $ # $k $r J$ d$ # '$ $ $" $~ # '$ "$ '$E $ # $ $L $" $F ... # $. 4B $ $$$*"""*b # '$ $. $$ $$ $F # "$ R$ $F $" $ # $k ?$ u* dF .$ # ^$. $$" z$ u$$$$e # #$b $E.dW@e$" ?$ # #$ .o$$# d$$$$c ?F # $ .d$$#" . zo$> #$r .uF # $L .u$*" $&$$$k .$$d$$F # $$" ""^"$$$P"$P9$ # JP .o$$$$u:$P $$ # $ ..ue$" "" $" # d$ $F $ # $$ ....udE 4B # #$ """"` $r @$ # ^$L '$ $F # RN 4N $ # *$b d$ # $$k $F # $$b $F # $"" $F # '$ $ # $L $ # '$ $ # $ $ # ......................................&&......................... ....................................&&&.......................... .................................&&&&............................ ...............................&&&&.............................. .............................&&&&&&.............................. ...........................&&&&&&....&&&..&&&&&&&&&&&&&&&........ ..................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.............. ................&...&&&&&&&&&&&&&&&&&&&&&&&&&&&&................. .......................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&......... ...................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&............... ..................&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&............ ...............&&&&&@ &&&&&&&&&&..&&&&&&&&&&&&&&&&&&&........... ..............&&&&&&&&&&&&&&&.&&....&&&&&&&&&&&&&..&&&&&......... ..........&&&&&&&&&&&&&&&&&&...&.....&&&&&&&&&&&&&...&&&&........ ........&&&&&&&&&&&&&&&&&&&.........&&&&&&&&&&&&&&&....&&&....... .......&&&&&&&&.....................&&&&&&&&&&&&&&&&.....&&...... ........&&&&&.....................&&&&&&&&&&&&&&&&&&............. ..........&...................&&&&&&&&&&&&&&&&&&&&&&&............ ................&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&............ ..................&&&&&&&&&&&&&&&&&&&&&&&&&&&&..&&&&&............ ..............&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&....&&&&&............ ...........&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&......&&&&............ .........&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.........&&&&............ .......&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...........&&&&............ ......&&&&&&&&&&&&&&&&&&&...&&&&&&...............&&&............. .....&&&&&&&&&&&&&&&&............................&&.............. ....&&&&&&&&&&&&&&&.................&&........................... ...&&&&&&&&&&&&&&&.....................&&&&...................... ...&&&&&&&&&&.&&&........................&&&&&................... ..&&&&&&&&&&&..&&..........................&&&&&&&............... ..&&&&&&&&&&&&...&............&&&.....&&&&...&&&&&&&............. ..&&&&&&&&&&&&&.................&&&.....&&&&&&&&&&&&&&........... ..&&&&&&&&&&&&&&&&..............&&&&&&&&&&&&&&&&&&&&&&&&......... ..&&.&&&&&&&&&&&&&&&&&.........&&&&&&&&&&&&&&&&&&&&&&&&&&&....... ...&&..&&&&&&&&&&&&.........&&&&&&&&&&&&&&&&...&&&&&&&&&&&&...... ....&..&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&...........&&&&&&&&..... .......&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&..............&&&&&&&.... .......&&&&&.&&&&&&&&&&&&&&&&&&..&&&&&&&&...&..........&&&&&&.... ........&&&.....&&&&&&&&&&&&&.....&&&&&&&&&&...........&..&&&&... .......&&&........&&&.&&&&&&&&&.....&&&&&.................&&&&... .......&&&...............&&&&&&&.......&&&&&&&&............&&&... ........&&...................&&&&&&.........................&&&.. .........&.....................&&&&........................&&.... ...............................&&&.......................&&...... ................................&&......................&&....... .................................&&.............................. ..................................&..............................
cpp#include <bits/stdc++.h>
using namespace std;
// #define int long long
const int M=5e5+5;
vector<int>f[M];
int dep[M],son[M],fa[M],sz[M],top[M];
void dfs1(int now,int t) {
dep[now]=dep[t]+1;
sz[now]=1;
fa[now]=t;
for(auto x:f[now]) {
if(x==t)continue;
dfs1(x,now);
sz[now]+=sz[x];
if(sz[x]>sz[son[now]]) son[now]=x;
}
}
void dfs2(int now,int t) {
top[now]=t;
if(son[now])dfs2(son[now],t);
for(auto x:f[now]) {
if(x==son[now]||x==fa[now])continue;
dfs2(x,x);
}
}
int lca(int x,int y) {
while(top[x]!=top[y]) {
if(dep[top[x]]<dep[top[y]])swap(x,y);
x=fa[top[x]];
}
return dep[x]<dep[y]?x:y;
}
void solve() {
int n,m,s;
cin>>n>>m>>s;
for(int i=1;i<n;++i) {
int x,y;
cin>>x>>y;
f[x].push_back(y);
f[y].push_back(x);
}
dfs1(s,s);
dfs2(s,s);
while (m--) {
int x,y;
cin>>x>>y;
cout<<lca(x,y)<<"\n";
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
solve();
return 0;
}
cpp#include <bits/stdc++.h>
using namespace std;
// #define int long long
const int M = 1e6 + 5;
int fa[M][22], dep[M];
vector<int> f[M];
inline void dfs(int x, int t)
{
fa[x][0] = t;
dep[x] = dep[t] + 1;
for (auto to : f[x])
if (to != t)
dfs(to, x);
} // 求 fa[i][0]
inline int lca(int x, int y)
{
if (dep[x] < dep[y])
swap(x, y);
for (int i = 20; i >= 0; i--)
{
if (dep[fa[x][i]] >= dep[y])
x = fa[x][i];
}
if (x == y)
return x;
for (int i = 20; i >= 0; i--)
{
if (fa[x][i] != fa[y][i])
{
x = fa[x][i];
y = fa[y][i];
}
}
return fa[x][0];
} // 求两个节点的 LCA
void solve()
{
int n, m, s;
cin >> n >> m >> s;
for (int i = 1; i < n; ++i)
{
int x, y;
cin >> x >> y;
f[x].push_back(y);
f[y].push_back(x);
}
dfs(s, 0);
for (int j = 1; (1 << j) <= n; ++j)
for (int i = 1; i <= n; ++i)
fa[i][j] = fa[fa[i][j - 1]][j - 1];
for (int i = 1; i <= m; ++i)
{
int x, y;
cin >> x >> y;
cout << lca(x, y) << "\n";
}
}
int main()
{
ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}