-
Notifications
You must be signed in to change notification settings - Fork 1
/
sjtu-oj1029.cpp
63 lines (59 loc) · 1.11 KB
/
sjtu-oj1029.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
getline(cin, s);
vector<vector<int> >v;
for (int i = 0; i < n; i++)
{
vector<int> vi;
getline(cin, s);
stringstream stream(s);
int ix;
while (stream >> ix)
vi.push_back(ix);
v.push_back(vi);
}
//for (int i = 0; i < v.size(); i++)
//{
// for (int j = 0; j < v[i].size(); j++)
// cout << v[i][j] << " ";
// cout << endl;
//}
vector<vector<int> > sh;
for (int i = 0; i < n; i++)
{
vector<int> vi;
vi.push_back(i);
sh.push_back(vi);
}
int a, b;
for (int i = 0; i < n - 1; i++)
{
cin >> a >> b;
a--;
b--;
for (int j = 0; j < sh[a].size(); j++)
sh[b].push_back(sh[a][j]);
sh[a].clear();
}
for (int i = 0; i < n; i++)
if (sh[i].size() > 0)
{
for (int j = 0; j < sh[i].size(); j++)
for (int k = 0; k < v[sh[i][j]].size(); k++)
{
cout << v[sh[i][j]][k];
if (j != sh[i].size() - 1 || k != v[sh[i][j]].size() - 1)
cout << " ";
}
break;
}
return 0;
}