当前位置:网站首页>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;
}
}
边栏推荐
- R language [logic control] [mathematical operation]
- 绕过open_basedir
- 10W word segmentation searches per second, the product manager raised another demand!!! (Collection)
- Go 語言的 Context 詳解
- Introduction to yarn (one article is enough)
- 【SQL实战】一条SQL统计全国各地疫情分布情况
- STM32按键状态机2——状态简化与增加长按功能
- yarn入门(一篇就够了)
- Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
- Bbox regression loss function in target detection -l2, smooth L1, IOU, giou, Diou, ciou, focal eiou, alpha IOU, Siou
猜你喜欢

Career experience feedback to novice programmers

从“跑分神器”到数据平台,鲁大师开启演进之路

JVM命令之 jstat:查看JVM統計信息

JVM命令之 jstack:打印JVM中线程快照

搞懂fastjson 对泛型的反序列化原理

Randomly generate session_ id

From "running distractor" to data platform, Master Lu started the road of evolution

Chain storage of stack

往图片添加椒盐噪声或高斯噪声

Deep clustering: joint optimization of depth representation learning and clustering
随机推荐
Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();
[shell] clean up nohup Out file
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略
JVM命令之 jstat:查看JVM统计信息
Bypass open_ basedir
【SQL实战】一条SQL统计全国各地疫情分布情况
Explication contextuelle du langage Go
EMMC打印cqhci: timeout for tag 10提示分析与解决
PowerPivot——DAX(函数)
The solution of a simple algebraic problem
Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture
980. 不同路径 III DFS
MySQL performance_ Schema common performance diagnosis query
职场经历反馈给初入职场的程序员
Bat instruction processing details
Chain storage of stack
make makefile cmake qmake都是什么,有什么区别?
980. Different path III DFS
PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
【日常训练--腾讯精选50】292. Nim 游戏