Created
February 2, 2015 14:00
-
-
Save ik11235/d9262380bb8707fb52e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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