Skip to content

Commit b2ee959

Browse files
authored
Create 1761.Minimum-Degree-of-a-Connected-Trio-in-a-Graph.cpp
1 parent f94c52e commit b2ee959

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class Solution {
2+
int c[401][401];
3+
public:
4+
int minTrioDegree(int n, vector<vector<int>>& edges)
5+
{
6+
for (auto e:edges)
7+
{
8+
c[e[0]][e[1]] = 1;
9+
c[e[1]][e[0]] = 1;
10+
}
11+
12+
vector<int> next[401];
13+
vector<int> next2[401];
14+
15+
for (auto e:edges)
16+
{
17+
int a = min(e[0], e[1]);
18+
int b = max(e[0], e[1]);
19+
next[a].push_back(b);
20+
next2[a].push_back(b);
21+
next2[b].push_back(a);
22+
}
23+
24+
int ret = INT_MAX;
25+
for (int x=1; x<=n; x++)
26+
{
27+
for (int i=0; i<next[x].size(); i++)
28+
for (int j=i+1; j<next[x].size(); j++)
29+
{
30+
int a = next[x][i];
31+
int b = next[x][j];
32+
if (c[a][b])
33+
ret = min(ret, (int)next2[x].size()-2+(int)next2[a].size()-2+(int)next2[b].size()-2);
34+
}
35+
}
36+
return ret==INT_MAX?-1:ret;
37+
}
38+
};

0 commit comments

Comments
 (0)