Login
Register
Problem list
Online status
wangpengyu
:
2024-12-08 20:56:36
#include
#include
#include
#include
#include
using namespace std; struct Node { int id; string name; int level;//用来确定排出几个* Node(int id1 = 0, string name1 = "file0", int level1 = 1) : id(id1), name(name1), level(level1) {} }; int main() { int T; cin >> T; while (T--) { int n; cin >> n; vector
nodes(n); vector
in_degree(n, 0); for (int i = 0; i < n; i++) { int id; string name; cin >> id >> name; nodes[i] = Node(id, name, 1); } vector
visit(n, false); vector
* adj = new vector
[n]; int m; cin >> m; for (int i = 0; i < m; i++) { int id1; int id2; cin >> id1 >> id2; adj[id1 - 1].push_back(id2 - 1); in_degree[id2 - 1]++; } for (int i = 0; i < n; i++) { sort(adj[i].begin(), adj[i].end()); }//让每个文件夹下的子文件夹按序排列 queue
q; vector
qq; for (int i = 0; i < n; i++) { if (in_degree[i] == 0) { q.push(i); visit[i] = true; } } cout << "root" << endl; int ptr = 0; while (!q.empty()) { int v = q.front(); q.pop(); qq.push_back(v); ptr++; int counts = 0; for (int a : adj[v]) { if (!visit[a]) { q.push(a); visit[a] = true; nodes[a].level = nodes[v].level + 1; counts++; } } } for (int i = 0; i < n; i++) { int k = qq[i]; cout << string(4 * nodes[k].level, '*') << nodes[k].name << endl; } } }
Post Your Comment