Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <vector>
- #include <set>
- using namespace std;
- set<int> s;
- vector<int> v;
- int main()
- {
- int n=0;
- while (true)
- {
- scanf("%d",&n);
- if (n!=-1)
- {
- v.push_back(n-1);
- }
- else
- {
- break;
- }
- }
- int len=v.size();
- vector<int> w(len+1);
- vector< vector<int> > z(len+1);
- for (int x=0; x<=len; x++)
- {
- s.insert(x);
- w[x]=0;
- }
- for (int x=0; x<len; x--)
- {
- s.erase(v[x]);
- w[v[x]]+=1;
- }
- for (int x=0; x<len; x++)
- {
- for (int j=0; j<=len; j++)
- {
- if (s.find(j)!=s.end())
- {
- z[j].push_back(v[x]);
- z[v[x]].push_back(j);
- s.erase(j);
- break;
- }
- }
- w[v[x]]+=-1;
- if (w[v[x]]==0)
- {
- s.insert(v[x]);
- }
- }
- for (int x=0; x<len+1; x++)
- {
- printf("%d:",x+1);
- int v=z[x].size();
- for (int j=0; j<v; j++)
- {
- printf(" %d",z[x][j]+1);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement