当前位置:网站首页>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;
}
}
边栏推荐
- 关于STC单片机“假死”状态的判别
- Determine whether the file is a DICOM file
- On the difference between FPGA and ASIC
- 产业金融3.0:“疏通血管”的金融科技
- Mysql-centos7 install MySQL through yum
- Flask 1.1.4 werkzeug1.0.1 analyse du code source: processus de démarrage
- nVisual网络可视化
- C. colonne Swapping [tri + Simulation]
- 数字IC面试总结(大厂面试经验分享)
- 云加速,帮助您有效解决攻击问题!
猜你喜欢
【日常训练--腾讯精选50】235. 二叉搜索树的最近公共祖先
Bat instruction processing details
Determine whether the file is a DICOM file
Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)
深度聚类:将深度表示学习和聚类联合优化
[SQL practice] a SQL statistics of epidemic distribution across the country
老板总问我进展,是不信任我吗?(你觉得呢)
Harmonyos practice - Introduction to development, analysis of atomized services
Reptile exercises (III)
随机推荐
PTA 天梯赛练习题集 L2-003 月饼 测试点2,测试点3分析
Personal imitation SSM framework
Industrial Finance 3.0: financial technology of "dredging blood vessels"
Mysql-centos7 install MySQL through yum
Value range of various datetimes in SQL Server 2008
JVM命令之- jmap:导出内存映像文件&内存使用情况
Win configuration PM2 boot auto start node project
Flask 1.1.4 werkzeug1.0.1 analyse du code source: processus de démarrage
PTA ladder game exercise set l2-004 search tree judgment
Input of native applet switches between text and password types
《ClickHouse原理解析与应用实践》读书笔记(6)
New Year Fireworks code plus copy, are you sure you don't want to have a look
jvm命令之 jcmd:多功能命令行
Red hat install kernel header file
Classic questions about data storage
往图片添加椒盐噪声或高斯噪声
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
SAP ABAP BDC (batch data communication) -018
How to improve website weight
Jinfo of JVM command: view and modify JVM configuration parameters in real time