forked from cielavenir/procon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tyama_icpc2013s4A(aizu2619).cpp
47 lines (44 loc) · 1.01 KB
/
tyama_icpc2013s4A(aizu2619).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <algorithm>
using namespace std;
//#define FLOAT
void dfs(int id,int depth,const map<int,string>&id2name,const map<int,deque<int> >&children){
cout<<string(depth,'.')<<id2name.at(id)<<endl;
if(children.find(id)!=children.end())for(auto &e:children.at(id)){
dfs(e,depth+1,id2name,children);
}
}
int main(){
map<int,string>id2name;
map<int,int>parent;
map<int,deque<int> >children;
int N,k;
string s;
cin>>N;
cin>>k>>s;
parent[1]=0;
id2name[1]=s;
#ifdef FLOAT
children[k].push_front(1);
#else
children[k].push_back(1);
#endif
for(int post=2;post<=N;post++){
cin>>k>>s;
parent[post]=k;
id2name[post]=s;
for(int cur=post;cur;cur=parent[cur]){
children[parent[cur]].erase(remove(children[parent[cur]].begin(),children[parent[cur]].end(),cur),children[parent[cur]].end());
#ifdef FLOAT
children[parent[cur]].push_front(cur);
#else
children[parent[cur]].push_back(cur);
break;
#endif
}
}
dfs(1,0,id2name,children);
}