505B. Mr. Kitayuta‘s Colorful Graph
生活随笔
收集整理的這篇文章主要介紹了
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 中的 视图和模型
- 下一篇: 若依框架入门一