Skip to content

Instantly share code, notes, and snippets.

@ik11235
Created February 2, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik11235/d9262380bb8707fb52e5 to your computer and use it in GitHub Desktop.
Save ik11235/d9262380bb8707fb52e5 to your computer and use it in GitHub Desktop.
class Fragile2 {
public:
int countgroup(vector<string> graph) {
bool flag[21];
memset(flag,true,sizeof(flag));
int n_size=0;
for(int i=0;i<graph.size();i++)
{
if(flag[i])
{
queue<int> qu;
flag[i]=false;
n_size++;
qu.push(i);
while(!qu.empty())
{
int now=qu.front();
qu.pop();
for(int j=0;j<graph[now].size();j++)
{
if(flag[j]&&graph[now][j]=='Y')
{
flag[j]=false;
qu.push(j);
}
}
}
}
}
return n_size;
}
int countPairs(vector<string> graph) {
int cnt=0;
int n_size=countgroup(graph);
for(int i=0;i<graph.size();i++)
for(int j=i+1;j<graph.size();j++)
{
vector<string> tmp=graph;
for(int ii=0;ii<graph.size();ii++)
for(int jj=0;jj<graph.size();jj++)
{
if(ii==i || jj==j ||
ii==j || jj==i)
tmp[ii][jj]='N';
}
if(n_size<countgroup(tmp)-2)
cnt++;
}
return cnt;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment