o.boj 1034 冥王星的故事II-占领岛国

冥王星的勇士zhao0057在征服岛国后,命令参谋长moyuji负责道路修建,面对复杂的建设与拆除任务,moyuji需要设计程序解决城市间连通性问题。

注:最近这一系列ACM的内容,都是2年多之前的代码,自己回顾一下。

冥王星的故事II-占领岛国
 
Submit: 1193   Accepted:362
Time Limit: 2000MS  Memory Limit: 65536K
Description
经过几年的战争,在H上将的带领上,冥王星的勇士们攻克了地球人称作日本的岛国,Pluto的Boss级人物zhao0057决定在那里建立一个根据地。然而,战争过后,这个地方已经是一片废墟,要想把根据地重新建立起来,第一件事情就是修路,zhao0057命令他的参谋长moyuji负责道路的修建,moyuji认为这是很简单的工作,因此他并没有制定一个详细的计划,每到一处就随意的修建道路,然后又会发觉某条路没有规划好,需要把它拆除。经过多次的修建拆除,他自己都弄不清楚到底哪些城市互相连通了,哪些没有。所谓连通,是指至少能找到一条从a到b的路径。现在,moyuji希望你帮他设计一个程序解决这个问题。

Input
首先是两个整数n(n< 100)和m,n表示城市的数目.
接着有m行,每行有三个数 D a b (0< a,b <= n a!=b),如果D=0 表示连接a、b之间的道路。如果D=1,表示撤除a、b之间的道路。(0 < a,b <=n)
然后是一个整数q(q<10),表示查询的次数。
接下来q行每行是两个整数a,b.表示询问a,b间是否连通

Output
对每次查询,如果a,b间是连通的输出yes,否则输出no

Sample Input

4 4
0 1 2
0 2 3
0 3 4
1 3 4
2
1 3
1 4

Sample Output

yes
no

Hint
moyuji先修建了三条道路1-2,2-3,3-4.然后又拆除了道路3-4.
这时候对于城市1,3。我们可以找到一条路径从1到3,即1-2-3。
而对于城市1,4。因为拆除了道路3-4,我们找不到一条这样的路径了。


Source
xiaolonghingis@Pluto
 
 
 
 
考查图的连通性,直接求闭包即可。就输入多了一些处理,因为能把之前建设的道路给销毁掉。
 
#include <iostream>

using namespace std;

int main()
{
    int city[100][100] = {0};
    int n, m, D, a, b;
    
    cin >> n >> m;
    
    for (int i = 1; i <= m; i++)
    {
        cin >> D >> a >> b;
        city[a][b] = city[b][a] = 1 - D;
        
    }
        
    for (int i = 1;i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                if (city[i][k] && city[k][j])
                    city[i][j] = city[j][i] = 1;
    
    cin >> m;
    
    for (int i = 1; i <= m; i++)
    {
        cin >> a >> b;
        if (city[a][b])
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }     
    // system("pause"); 
}


Collecting fasttext Using cached fasttext-0.9.3.tar.gz (73 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Collecting pybind11>=2.2 (from fasttext) Using cached pybind11-2.13.6-py3-none-any.whl.metadata (9.5 kB) Requirement already satisfied: setuptools>=0.7.0 in d:\fasttextrego\fasttext_bio_glut\lib\site-packages (from fasttext) (78.1.1) Requirement already satisfied: numpy in d:\fasttextrego\fasttext_bio_glut\lib\site-packages (from fasttext) (2.0.1) Using cached pybind11-2.13.6-py3-none-any.whl (243 kB) Building wheels for collected packages: fasttext Building wheel for fasttext (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for fasttext (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [50 lines of output] C:\Users\Lenovo\AppData\Local\Temp\pip-build-env-boj2tm39\overlay\Lib\site-packages\setuptools\dist.py:599: SetuptoolsDeprecationWarning: Invalid dash-separated key 'description-file' in 'metadata' (setup.cfg), please use the underscore name 'description_file' instead. !! ******************************************************************************** Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead. (Affected: fasttext). By 2026-Mar-03, you need to update your project and remove deprecated calls or your builds will no longer be supported. See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details. ******************************************************************************** !! opt = self._enforce_underscore(opt, section) C:\Users\Lenovo\AppData\Local\Temp\pip-build-env-boj2tm39\overlay\Lib\site-packages\setuptools\dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: MIT License See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-312\fasttext copying python\fasttext_module\fasttext\FastText.py -> build\lib.win-amd64-cpython-312\fasttext copying python\fasttext_module\fasttext\__init__.py -> build\lib.win-amd64-cpython-312\fasttext creating build\lib.win-amd64-cpython-312\fasttext\util copying python\fasttext_module\fasttext\util\util.py -> build\lib.win-amd64-cpython-312\fasttext\util copying python\fasttext_module\fasttext\util\__init__.py -> build\lib.win-amd64-cpython-312\fasttext\util creating build\lib.win-amd64-cpython-312\fasttext\tests copying python\fasttext_module\fasttext\tests\test_configurations.py -> build\lib.win-amd64-cpython-312\fasttext\tests copying python\fasttext_module\fasttext\tests\test_script.py -> build\lib.win-amd64-cpython-312\fasttext\tests copying python\fasttext_module\fasttext\tests\__init__.py -> build\lib.win-amd64-cpython-312\fasttext\tests running build_ext building 'fasttext_pybind' extension creating build\temp.win-amd64-cpython-312\Release\python\fasttext_module\fasttext\pybind creating build\temp.win-amd64-cpython-312\Release\src "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\Lenovo\AppData\Local\Temp\pip-build-env-boj2tm39\overlay\Lib\site-packages\pybind11\include -IC:\ Users\Lenovo\AppData\Local\Temp\pip-build-env-boj2tm39\overlay\Lib\site-packages\pybind11\include -Isrc -ID:\FastTextReGo\fasttext_bio_glut\include -ID:\FastTextReGo\fasttext_bio_glut\Include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /EHsc /Tppython/fasttext_module/fasttext/pybind/fasttext_pybind.cc /Fobuild\temp.win-amd64-cpython-312\Release\python\fasttext_module\fasttext\pybind\fasttext_pybind.obj /EHsc /DVERSIO N_INFO=\\\"0.9.3\\\" fasttext_pybind.cc c:\users\lenovo\appdata\local\temp\pip-install-hi0ftxzy\fasttext_d672f1ad14674ffe9f3c149b60977761\src\dictionary.h(16): fatal error C1083: Cannot open include file: 'string_view': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for fasttext Failed to build fasttext ERROR: Failed to build installable wheels for some pyproject.toml based projects (fasttext)
最新发布
06-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值