Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int n;
- int graph[10000][10000];
- void dfs(int start) {
- stack<pair<int, int>> st;
- vector<int> used(n);
- st.push(make_pair(start, 0));
- used[start] = 1;
- while (!st.empty()) {
- if (st.top().second == 0) {
- cout << st.top().first << endl;
- }
- for (pair<int, int> & cur = st.top(); cur.second < n; ++cur.second) {
- if (graph[cur.first][cur.second] && !used[cur.second]) {
- st.push(make_pair(cur.second, 0));
- used[cur.second] = 1;
- break;
- }
- }
- if (st.top().second == n) {
- st.pop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement