Skip to content

Instantly share code, notes, and snippets.

@dazza
Created September 13, 2008 08:11
Show Gist options
  • Save dazza/10581 to your computer and use it in GitHub Desktop.
Save dazza/10581 to your computer and use it in GitHub Desktop.
#include <fstream>
using namespace std;
class node
{
public:
node(){next=NULL;j=0;persent=0;}
int j;
int persent;
node* next;
};
node* array[101];
int visited[101];
int cx[101];
void dfs(int);
int main()
{
ifstream fin("concom.in");
ofstream fout("concom.out");
int n;
fin>>n;
for ( int i = 1 ; i<=n ;i++ )
{
int ii; fin>>ii;
if (!array[ii])
{
array[ii] = new node();
fin>>array[ii]->j;
fin>>array[ii]->persent;
}
else
{
node* p = array[ii];
node* q;
while (p)
{
q = p;
p = p->next;
}
q->next = new node();
q = q->next;
fin>>q->j;
fin>>q->persent;
}
}
//int kk = array[1]->j;
//
for (int i = 1 ;i<=100; i++)
{
for (int k=1; k<=100 ; k++)
{
cx[k] = 0;
visited[k] = 0;
}
dfs(i);
for (int k = 1 ;k<=100; k++)
{
if (cx[k]>50&&k!=i)
{
fout<<i<<' '<<k<<endl;
}
}
}
fin.close();
fout.close();
return 0;
}
void dfs(int i)
{
if (visited[i])
return;
visited[i] = 1;
node* p = array[i];
while (p)
{
cx[p->j] += p->persent;
if ( cx[p->j] > 50 )
{
dfs( p->j );
}
p = p->next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment