Advertisement
yuhung94

tioj 1069

Oct 28th, 2022 (edited)
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #pragma GCC optimzize("Ofast,no-stack-protector")
  2. #include<bits/stdc++.h>
  3. #define int long long
  4. #define quick ios::sync_with_stdio(0);cin.tie(0);
  5. #define rep(x,a,b) for(int x=a;x<=b;x++)
  6. #define repd(x,a,b) for(int x=a;x>=b;x--)
  7. #define lowbit(x) (x&-x)
  8. #define sz(x) (int)(x.size())
  9. #define F first
  10. #define S second
  11. #define all(x) x.begin(),x.end()
  12. #define mp make_pair
  13. #define eb emplace_back
  14. using namespace std;
  15. typedef pair<int,int> pii;
  16. void debug(){
  17.     cout<<"\n";
  18. }
  19. template <class T,class ... U >
  20. void debug(T a, U ... b){
  21.     cout<<a<<" ",debug(b...);
  22. }
  23. const int N=2e3+7;
  24. const int INF=1e18;
  25. vector<int> v[N];//X的鄰點
  26. int match[N]; // Y所匹配的節點
  27. bool vis[N]; //在這次尋找中是否被走過
  28. int dfs(int x){
  29.     for(int y:v[x]){
  30.         if(vis[y]) continue;
  31.         vis[y]=true;
  32.         if(match[y]==-1||dfs(match[y])){
  33.             match[y]=x;
  34.             return true;
  35.         }
  36.     }
  37.     return false;
  38. }
  39. int bipartiteMatching(int n){
  40.     fill(match,match+n+1,-1);
  41.     int ans=0;
  42.     rep(i,1,n){
  43.         fill(vis,vis+n+1,0);
  44.         if(dfs(i)) ans++;
  45.     }
  46.     return ans;
  47. }
  48. struct edge{
  49.     int t,x,y;
  50. }e[N];
  51. signed main(){
  52.     quick
  53.     int n;
  54.     cin>>n;
  55.     while(n--){
  56.         int m;
  57.         cin>>m;
  58.         rep(i,1,m){
  59.             v[i].clear();
  60.             cin>>e[i].t>>e[i].x>>e[i].y;
  61.         }
  62.         rep(i,1,m){
  63.             rep(j,1,m){
  64.                 if(i!=j&&e[i].t+abs(e[i].x-e[j].x)+abs(e[i].y-e[j].y)<=e[j].t){
  65.                     v[i].eb(j);
  66.                 }
  67.             }
  68.         }
  69.         cout<<m-bipartiteMatching(m)<<"\n";
  70.     }
  71.     return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement