mr_dot_convict

1194-Machine-Schedule-UVa-mr.convict

May 31st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.64 KB | None | 0 0
  1. /*author* Priyanshu Shrivastav (from IIT Palakkad) *
  2.  * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
  3.  * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
  4.  * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
  5.  * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
  6. When I wrote this, only God and I understood what I was doing
  7.  ** * * * * * * * Now, only God knows * * * * * * */
  8. #include         <bits/stdc++.h>
  9. using namespace std;
  10. #pragma GCC      optimize ("Ofast")
  11. #pragma GCC      optimize ("unroll-loops")
  12. #pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  13.  
  14. #define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
  15. #define PREC     cout.precision (10); cout << fixed
  16. #define bg(x)    " [ " << #x << " : " << (x) << " ] "
  17. #define x        first
  18. #define y        second
  19.  
  20. #define debug(args...) { \
  21.    string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
  22.    stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
  23. }
  24. void err(istream_iterator<string> it) { it->empty();
  25.    cerr << " (Line : " << __LINE__ << ")" << '\n';
  26. }
  27. template<typename T, typename... Args>
  28. void err(istream_iterator<string> it, T a, Args... args) {
  29.     cerr << " [ " <<  *it << " : " << a  << " ] "<< ' ';
  30.     err(++it, args...);
  31. }
  32.  
  33. const int N = 200;
  34.  
  35. bool vis[N];
  36. int match[N];
  37. vector < vector <int> > Adj;
  38. int n, nl, nr; // first 0, ..., nl - 1 vertices in left nl, ..., nr - 1 in right
  39.  
  40. void init() {
  41.    n = nl + nr;
  42.    assert(n);
  43.    Adj.assign(n, vector <int> ());
  44.    for (int i = 0; i < n; ++i)
  45.       vis[i] = false, match[i] = -1;
  46. }
  47.  
  48. inline void add_edge(int u, int v) {
  49.    Adj[u].push_back(v);
  50. }
  51.  
  52. bool augment(int u) {
  53.    if (vis[u]) return false;
  54.    vis[u] = true;
  55.  
  56.    for (int v : Adj[u]) {
  57.       if (match[v] == -1 || augment(match[v])) {
  58.          match[v] = u;
  59.          return true;
  60.       }
  61.    }
  62.    return false;
  63. }
  64.  
  65. int MCBM() {
  66.    assert (nl + nr == n);
  67.    int mcbm = 0;
  68.  
  69.    for (int u = 0; u < nl; ++u) { // in left set
  70.       fill(vis, vis + n, false);
  71.       mcbm += augment(u);
  72.    }
  73.    return mcbm;
  74. }
  75.  
  76. int mac_a_size, mac_b_size, jobs;
  77. void read() {
  78.  
  79.    nl = mac_a_size, nr = mac_b_size;
  80.    init();
  81.  
  82.    int idx, mode_x, mode_y;
  83.    for (int i = 0; i < jobs; ++i) {
  84.       cin >> idx >> mode_x >> mode_y;
  85.       assert (mode_x < mac_a_size && mode_y < mac_b_size);
  86.       if (!(mode_x && mode_y)) continue; // if on mode 0 then don't need to count
  87.       add_edge (mode_x, mode_y);
  88.    }
  89.  
  90.    cout << MCBM() << '\n';
  91. }
  92.  
  93. signed main() {
  94.    IOS; PREC;
  95.    while (cin >> mac_a_size >> mac_b_size >> jobs, mac_a_size) {
  96.       read();
  97.    }
  98.    return EXIT_SUCCESS;
  99. }
Add Comment
Please, Sign In to add comment