Beispiel #1
0
int top(si &s1, si& s2){
  if(!s2.empty())
    return s2.top();
  if(s1.empty())
    return -1;
  while(!s1.empty()){
    s2.push(s1.top());
    s1.pop();

  }
  return s2.top();
}
Beispiel #2
0
bool solve()
{
  int mg,mm;
  while(!g.empty() && !m.empty())
  {
    mg=*g.begin();
    mm=*m.begin();
    if(mg<mm) 
      g.erase(g.begin());
    else 
      m.erase(m.begin());
  }

  return m.empty();
}
Beispiel #3
0
void pop(si &s1, si &s2){
  if(!s2.empty()){
    s2.pop();
    return;
  }
  if(s1.empty())
    return;
  while(true){
  int i=s1.top();
  s1.pop();
  if(s1.empty())
    return;
  s2.push(i);
  }
}
int main()
{
    int n,m,x,y,i;
    while(scanf("%d%d", &n, &m)!=EOF)
    {
        vs.clear();
        for(i=0; i<n; ++i) v[i].clear();

        for(i=0; i<m; ++i)
        {
            scanf("%d%d", &x, &y);
            --x; --y;
            v[x].push_back(y);
            v[y].push_back(x);
        }

        for(i=0; i<n; ++i)
        {
            s1.insert(i);
            sort(v[i].begin(), v[i].end());
        }

        while(!s1.empty())
        {
            x=*s1.begin();
            s1.erase(x);

            s2.clear();

            q.push(x);

            while(!q.empty())
            {
                x=q.front(); q.pop();
                s2.insert(x);

                for(sit=s1.begin(); sit != s1.end();)
                {
                    y=*sit;
                    ++sit;
                    if(!binary_search(v[x].begin(), v[x].end(), y))
                    {
                        q.push(y); s1.erase(y);
                    }
                }
            }
            vs.push_back(s2);
        }
        printf("%u\n", vs.size());
        for(i=0; i<vs.size(); ++i)
        {
            printf("%u", vs[i].size());
            for(sit=vs[i].begin(); sit != vs[i].end(); ++sit)
            {
                printf(" %d", *sit+1);
            }
            puts("");
        }
    }
    return 0;
}