Advertisement
Korotkodul

21-22_N5_v1

Mar 24th, 2023 (edited)
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. #define pb push_back
  9.  
  10.  
  11. map <char, vector <char> > G;
  12. map <char, int> clr;
  13.  
  14. void unlock(char proc, char rec) {
  15.     auto pointer = find(begin(G[rec]), end(G[rec]), proc);
  16.     G[rec].erase(pointer);
  17. }
  18.  
  19. void lock(char proc, char rec) {
  20.     G[rec].pb(proc);
  21. }
  22.  
  23.  
  24. void get_cycle(char v) {
  25.     char start = v;
  26.     vector <char> cycle = {v};
  27.     v = G[v][0];
  28.     while (v != start) {
  29.         cycle.pb(v);
  30.         v = G[v][0];
  31.     }
  32.     vector <char> ans;
  33.     for (char l: cycle) {
  34.         if (l - '0' >= 0 && l - '0' <= 9) {
  35.             ans.pb(l);
  36.         }
  37.     }
  38.     sort(ans.begin(), ans.end());
  39.     cout << "DEADLOCK\n";
  40.     for (char l: ans) {
  41.         cout << l << " ";
  42.     }
  43.     cout << "\n";
  44.     exit(0);
  45. }
  46.  
  47. void dfs(char v) {
  48.     clr[v] = 1;
  49.     for (char u: G[v]) {
  50.         if (clr[u] == 0) {
  51.             dfs(u);
  52.         }
  53.         else {
  54.             get_cycle(u);
  55.         }
  56.     }
  57.     clr[v] = 2;
  58. }
  59.  
  60.  
  61. int main()
  62. {
  63.  
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement