通过图中所有边恰好一次且行遍所有顶点的通路称为欧拉通路。
通过图中所有边恰好一次且行遍所有顶点的回路称为欧拉回路。
具有欧拉回路的无向图称为欧拉图。
具有欧拉通路但不具有欧拉回路的无向图称为半欧拉图。
https://leetcode-cn.com/problems/reconstruct-itinerary/solution/zhong-xin-an-pai-xing-cheng-by-leetcode-solution/
class Solution {
public:
unordered_map<string, priority_queue<string, vector<string>, greater<string>>> map;
vector<string> st;
void dfs(const string &s){
while(map.count(s) && map[s].size() > 0){
string temp = map[s].top();
map[s].pop();
dfs(move(temp));
}
st.emplace_back(s);
}
vector<string> findItinerary(vector<vector<string>>& tickets) {
for(auto &it : tickets){
map[it[0]].emplace(it[1]);//try insert
}
dfs("JFK");
reverse(st.begin(), st.end());
return st;
}
};