当前位置:网站首页>693. 行程排序
693. 行程排序
2022-07-07 01:08:00 【Ray.C.L】
思路:找起点(入度为0),遍历一遍
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main()
{
int T;
cin >> T;
for(int i = 1; i <= T; i ++){
int n;
cin >> n;
unordered_map<string, string> next;
unordered_set<string> S;
while(n --){
string a, b;
cin >> a >> b;
next[a] = b;
S.insert(b);
}
string head;
for(auto& [a, b] : next)
if(!S.count(a)){
head = a;
break;
}
printf("Case #%d: ",i);
while(next[head].size()){
cout << head << '-' << next[head] << ' ';
head = next[head];
}
cout << endl;
}
}
边栏推荐
- 一名普通学生的大一总结【不知我等是愚是狂,唯知一路向前奔驰】
- Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)
- cf:C. Column Swapping【排序 + 模拟】
- Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
- SAP Spartacus checkout 流程的扩展(extend)实现介绍
- CTFshow--常用姿势
- DC-7靶机
- PTA 天梯赛练习题集 L2-002 链表去重
- I didn't know it until I graduated -- the principle of HowNet duplication check and examples of weight reduction
- 成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
猜你喜欢
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
If you don't know these four caching modes, dare you say you understand caching?
Jinfo of JVM command: view and modify JVM configuration parameters in real time
VScode进行代码补全
数据中心为什么需要一套基础设施可视化管理系统
【FPGA教程案例13】基于vivado核的CIC滤波器设计与实现
Apple CMS V10 template /mxone Pro adaptive film and television website template
Reptile exercises (III)
Red Hat安装内核头文件
PowerPivot - DAX (function)
随机推荐
Chain storage of stack
Vscode for code completion
绕过open_basedir
Ten stages of becoming a Senior IC Design Engineer. What stage are you in now?
Ctfshow-- common posture
[InstallShield] Introduction
POI excel export, one of my template methods
深度聚类:将深度表示学习和聚类联合优化
C. colonne Swapping [tri + Simulation]
Wechat applet Bluetooth connects hardware devices and communicates. Applet Bluetooth automatically reconnects due to abnormal distance. JS realizes CRC check bit
Mac version PHP installed Xdebug environment (M1 version)
PTA 天梯赛练习题集 L2-002 链表去重
make makefile cmake qmake都是什么,有什么区别?
Financial risk control practice - decision tree rule mining template
Go language context explanation
SAP Spartacus checkout 流程的扩展(extend)实现介绍
成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
Check Point:企业部署零信任网络(ZTNA)的核心要素
Jstat of JVM command: View JVM statistics
On the discrimination of "fake death" state of STC single chip microcomputer