Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <vector>
- #include <string>
- #include <algorithm>
- using namespace std;
- #define pb push_back
- map <char, vector <char> > G;
- map <char, int> clr;
- void unlock(char proc, char rec) {
- auto pointer = find(begin(G[rec]), end(G[rec]), proc);
- G[rec].erase(pointer);
- }
- void lock(char proc, char rec) {
- G[rec].pb(proc);
- }
- void get_cycle(char v) {
- char start = v;
- vector <char> cycle = {v};
- v = G[v][0];
- while (v != start) {
- cycle.pb(v);
- v = G[v][0];
- }
- vector <char> ans;
- for (char l: cycle) {
- if (l - '0' >= 0 && l - '0' <= 9) {
- ans.pb(l);
- }
- }
- sort(ans.begin(), ans.end());
- cout << "DEADLOCK\n";
- for (char l: ans) {
- cout << l << " ";
- }
- cout << "\n";
- exit(0);
- }
- void dfs(char v) {
- clr[v] = 1;
- for (char u: G[v]) {
- if (clr[u] == 0) {
- dfs(u);
- }
- else {
- get_cycle(u);
- }
- }
- clr[v] = 2;
- }
- int main()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement