当前位置:
首页 >
505B. Mr. Kitayuta‘s Colorful Graph
发布时间:2023/12/10
75
豆豆
生活随笔
收集整理的这篇文章主要介绍了
505B. Mr. Kitayuta‘s Colorful Graph
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
B. Mr. Kitayuta’s Colorful Graph:题目
一开始就像到了DFS,并查集也不难想到。 弗洛伊德算法倒是不容易想到,平时不这么用。。。。。 #include <bits/stdc++.h> using namespace std; #define int long long // vector<int> a((int)6e5); // vector<int> b((int)6e5), c((int)6e5); const int mod = 1e9 + 7; int mp[111][111][111]; signed main() {int n, m;cin >> n >> m; int a, b, c;for (int i = 0; i < m; i++){cin >> a >> b >> c;mp[a][b][c] = mp[b][a][c] = 1;}for (int h = 1; h <= m; h++) //颜色for (int k = 1; k <= n; k++)for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)mp[i][j][h] |= mp[i][k][h]&mp[k][j][h];int q;cin>>q;while (q--){int u,v,res = 0;cin>>u>>v;for (int i=1;i<=m;i++)if (mp[u][v][i]||mp[v][u][i]) res++;cout<<res<<endl;}}总结
以上是生活随笔为你收集整理的505B. Mr. Kitayuta‘s Colorful Graph的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Laravel 中的 视图和模型
- 下一篇: 若依框架入门一