当前位置: 首页 > news >正文

黄石做网站公司北京百度科技有限公司电话

黄石做网站公司,北京百度科技有限公司电话,做满屏网站的尺寸,好的版式设计网站题目传送门 1 /*2 题意&#xff1a;两点之间有不同颜色的线连通&#xff0c;问两点间单一颜色连通的路径有几条3 DFS&#xff1a;暴力每个颜色&#xff0c;以u走到v为结束标志&#xff0c;累加条数4 注意&#xff1a;无向图5 */6 #include <cstdio>7 #includ…

 

题目传送门

 1 /*
 2     题意:两点之间有不同颜色的线连通,问两点间单一颜色连通的路径有几条
 3     DFS:暴力每个颜色,以u走到v为结束标志,累加条数
 4     注意:无向图
 5 */
 6 #include <cstdio>
 7 #include <iostream>
 8 #include <algorithm>
 9 #include <cstring>
10 #include <string>
11 #include <vector>
12 using namespace std;
13 
14 const int MAXN = 1e2 + 10;
15 const int INF = 0x3f3f3f3f;
16 int n, m;
17 bool vis[MAXN];
18 vector<pair<int, int> > V[MAXN];
19 
20 bool DFS(int u, int v, int c)
21 {
22     vis[u] = true;
23     if (u == v)    return true;
24     for (int i=0; i<V[u].size (); ++i)
25     {
26         pair<int, int>  p = V[u][i];
27         if (p.second == c && !vis[p.first])
28         {
29             if (DFS (p.first, v, c))    return true;
30         }
31     }
32 
33     return false;
34 }
35 
36 int main(void)        //Codeforces Round #286 (Div. 2) B - Mr. Kitayuta's Colorful Graph
37 {
38     //freopen ("B.in", "r", stdin);
39 
40     while (scanf ("%d%d", &n, &m) == 2)
41     {
42         for (int i=1; i<=m; ++i)
43         {
44             int u, v, c;
45             scanf ("%d%d%d", &u, &v, &c);
46             V[u].push_back (make_pair (v, c));
47             V[v].push_back (make_pair (u, c));
48         }
49         int q;    scanf ("%d", &q);
50         while (q--)
51         {
52             int u, v;    scanf ("%d%d", &u, &v);
53             int ans = 0;
54             for (int i=1; i<=m; ++i)
55             {
56                 memset (vis, false, sizeof (vis));
57                 if (DFS (u, v, i))    ans++;
58             }
59             printf ("%d\n", ans);
60         }
61     }
62 
63     return 0;
64 }
 1 /*
 2     并查集:开在结构体的并查集,进行如下的两个操作
 3     uf[c].Union (u, v);    uf[i].same (u, v)
 4 */
 5 #include <cstdio>
 6 #include <iostream>
 7 #include <algorithm>
 8 #include <cstring>
 9 #include <vector>
10 using namespace std;
11 
12 const int MAXN = 1e2 + 10;
13 const int INF = 0x3f3f3f3f;
14 struct UF
15 {
16     int rt[MAXN];
17     void init(void)    {memset (rt, -1, sizeof (rt));}
18 
19     int Find(int x)    {return (rt[x] == -1) ? x : rt[x] = Find (rt[x]);}
20 
21     void Union(int x, int y)
22     {
23         int tx = Find (x);
24         int ty = Find (y);
25         if (tx > ty)    rt[ty] = tx;
26         else if (tx < ty)    rt[tx] = ty;
27     }
28 
29     bool same(int x, int y)
30     {
31         return (Find (x) == Find (y));
32     }
33 }uf[MAXN];
34 int n, m;
35 
36 int main(void)        //Codeforces Round #286 (Div. 2) B - Mr. Kitayuta's Colorful Graph
37 {
38     //freopen ("B.in", "r", stdin);
39 
40     while (scanf ("%d%d", &n, &m) == 2)
41     {
42         for (int i=1; i<=m; ++i)    uf[i].init ();
43         for (int i=1; i<=m; ++i)
44         {
45             int u, v, c;
46             scanf ("%d%d%d", &u, &v, &c);
47             uf[c].Union (u, v);
48         }
49         int q;    scanf ("%d", &q);
50         while (q--)
51         {
52             int u, v;    scanf ("%d%d", &u, &v);
53             int ans = 0;
54             for (int i=1; i<=m; ++i)
55             {
56                 if (uf[i].same (u, v))    ans++;
57             }
58             printf ("%d\n", ans);
59         }
60     }
61 
62     return 0;
63 }
并查集

 

转载于:https://www.cnblogs.com/Running-Time/p/4512405.html

http://www.lbrq.cn/news/2505619.html

相关文章:

  • 惠东网页定制网站seo工具
  • 做公司网站需要几天百度指数怎么分析
  • 门户型网站都有哪些怎么网络推广自己业务
  • 给艺术家做网站的工作阿里云建网站
  • 衡水网站建设服务电商怎么做新手入门
  • 爱网站在线观看视频文山seo公司
  • 齐大胜请于果做网站是第几集免费网站建设哪家好
  • 容易做的网站百度搜索引擎网址
  • 贵州网络推广咨询富阳网站seo价格
  • 工控机做网站服务器东莞疫情最新通告
  • 嵌入式培训一般多少钱seo整站优化哪家专业
  • wordpress边栏尺寸优化软件
  • wordpress 弹出窗口武汉seo引擎优化
  • 从哪里下载wordpress整站外包优化公司
  • 东莞网站建设网络推广站长工具的使用seo综合查询运营
  • 在哪可以接企业网站建设的活福州网络推广运营
  • 连云港网站优化公司百度查重入口
  • 网站开发哪些公司保定seo推广
  • 无锡网站建设外贸互联网广告是做什么的
  • 做展板好的网站seo技术外包 乐云践新专家
  • dw制作学校官网页面seo快速排名系统
  • 做网站的为什么不给域名和密码巢湖seo推广
  • 网站建设消费者群体分析业务多平台怎么样
  • dw网页制作教程个人网站云南网络推广公司排名
  • 建设网站怎样做效果好的关键词如何优化
  • 分类信息网站建设方案网站免费客服系统
  • 开发网站那个好google站长工具
  • 龙城网站建设外包网
  • 有什么好的网站做旅行计划seo工具包括
  • 简繁英3合1企业网站生成管理系统V1.6常见的网络营销工具
  • B 站搜一搜关键词优化:精准触达用户的流量密码
  • 安装redis
  • java--WebSocket简单介绍
  • 机器学习特征选择 explanation and illustration of ANOVA
  • java开闭原则 open-closed principle
  • 渲染篇(二):解密Diff算法:如何用“最少的操作”更新UI