ccf 2017-09-04 通信网络 图的遍历

中文题意,不在重复。

开始时用的传递闭包思想,三层循环,结果给了35分,超时了。

后来,看了别人的代码,发现暴力搜图就可以了。

我们只需遍历n个点(发现n才1000。。。),每次都将此时的节点当做起点,然后开始查询通过此点能到达的所有点。

代码:


#include
#include
#include
#include
#include
using namespace std;
int flag[1005][1005];
int vis[1005];
vectorV[1005];
void dfs(int a,int t)
{
    vis[a]=1;
    flag[a][t]=flag[t][a]=1;
    for(int i=0;i


你可能感兴趣的:(CCF,暴力)