How to maintain the order while printing?

#include <bits/stdc++.h>
using namespace std;

void dfs(string str, map<string, list> &mp, map<string, bool> &vis, list& vec) {
vis[str] = true;

for (auto nbr : mp[str]) {
	if (!vis[nbr]) {
		dfs(nbr, mp, vis, vec);
	}
}
vec.push_front(str);

}

void solve() {

//int n;
//while(cin >> n) {
int num;
cin >> num;
string str;
for (int i = 0; i < num; i++) {
	cin >> str;
}

map<string, list<string>> mp;

int m;
cin >> m;

for (int i = 0; i < m; i++) {
	string x, y;
	cin >> x >> y;
	mp[y].push_back(x);
}

map<string, bool> vis;

for (auto str : mp) {
	vis[str.first] = false;
}
list<string> vec;
for (auto str : mp) {
	if (!vis[str.first]) {
		dfs(str.first, mp, vis, vec);
	}
}

for (auto str : vec) {
	cout << str << " ";
}

}
//}
//}

int main() {

#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif

solve();

}

which order are you talking about?
Case #1: Vivek should drink beverages in this order: a b c d e f s t.

Case #2: Vivek should drink beverages in this order: s a b e f c d t.
like here
case #1 and case #2 is mentioned
in that sense?
if yes then that is simply the test case number u are handling currently

although looking at ur code, the input format is wrong