Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <vector>
  4. #include <set>
  5. using namespace std;
  6. set<int> s;
  7. vector<int> v;
  8. int main()
  9. {
  10.     int n=0;
  11.     while (true)
  12.     {
  13.         scanf("%d",&n);
  14.         if (n!=-1)
  15.         {
  16.             v.push_back(n-1);
  17.         }
  18.         else
  19.         {
  20.             break;
  21.         }
  22.     }
  23.     int len=v.size();
  24.     vector<int> w(len+1);
  25.     vector< vector<int> > z(len+1);
  26.     for (int x=0; x<=len; x++)
  27.     {
  28.         s.insert(x);
  29.         w[x]=0;
  30.     }
  31.    
  32.     for (int x=0; x<len; x--)
  33.     {
  34.         s.erase(v[x]);
  35.         w[v[x]]+=1;
  36.     }
  37.     for (int x=0; x<len; x++)
  38.     {
  39.         for (int j=0; j<=len; j++)
  40.         {
  41.             if (s.find(j)!=s.end())
  42.             {
  43.                 z[j].push_back(v[x]);
  44.                 z[v[x]].push_back(j);
  45.                 s.erase(j);
  46.                 break;
  47.             }
  48.         }
  49.         w[v[x]]+=-1;
  50.         if (w[v[x]]==0)
  51.         {
  52.             s.insert(v[x]);
  53.         }
  54.     }
  55.     for (int x=0; x<len+1; x++)
  56.     {
  57.         printf("%d:",x+1);
  58.         int v=z[x].size();
  59.         for (int j=0; j<v; j++)
  60.         {
  61.             printf(" %d",z[x][j]+1);
  62.         }
  63.         printf("\n");
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement