struct Node { Node *pre; std::unordered_multiset<Node*>m_next; int value; Node(const int&x) :pre(nullptr), value(x) { } }; int main() { int n; cin >> n; std::unordered_multimap<int, Node*>m_Nodes; for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; if (m_Nodes.find(a) != m_Nodes.end()) { auto it = m_Nodes.find(a); Node *m_tempnode = new Node(b); it->second->m_next.insert(m_tempnode); m_Nodes.insert(std::pair<int, Node*>(b, m_tempnode)); m_tempnode->pre = it->second; } else { Node *m_tempnode = new Node(a); Node *m_tempnode2 = new Node(b); m_Nodes.insert(std::pair<int, Node*>(a, m_tempnode)); m_Nodes.insert(std::pair<int, Node*>(b, m_tempnode2)); m_tempnode->m_next.insert(m_tempnode2); m_tempnode2->pre = m_tempnode; } } 转下
点赞 评论

相关推荐

斑驳不同:还为啥暴躁 假的不骂你骂谁啊
点赞 评论 收藏
分享
牛客网
牛客企业服务