#include #include #include using namespace std; using namespace __gnu_pbds; #define debug(x) cerr << '[' << (#x) << "] = " << x << '\n'; template using ordered_set = tree , rb_tree_tag , tree_order_statistics_node_update> ; const int maxn = 1005; vector,char>>cows; vectorans(maxn, -1), will_go(maxn, 1e9), stopper(maxn, -2); vectorg[maxn], sub(maxn, 0); int n; void dfs(int node) { if(ans[node]!=-1) return; for(auto it : g[node]) { dfs(it); sub[node] += sub[it]; } ans[node] = sub[node]; ++sub[node]; } bool possible_stopper(int i, int j) { if(cows[i].second==cows[j].second) return false; if(cows[i].second=='E') { if(cows[j].first.second > cows[i].first.second) return false; if(cows[j].first.first < cows[i].first.first) return false; if(cows[j].first.first - cows[i].first.first <= cows[i].first.second - cows[j].first.second) return false; } else { if(cows[j].first.first > cows[i].first.first) return false; if(cows[j].first.second < cows[i].first.second) return false; if(cows[j].first.second - cows[i].first.second <= cows[i].first.first - cows[j].first.first) return false; } return true; } void AddEdge(int u, int v) { g[u].push_back(v); } void check(int i) { for(int j=0; j cows[j].first.first - cows[i].first.first) will_go[i] = cows[j].first.first - cows[i].first.first, stopper[i] = j; } } else { if(cows[j].first.first + will_go[j] > cows[i].first.first) { if(will_go[i] > cows[j].first.second - cows[i].first.second) will_go[i] = cows[j].first.second - cows[i].first.second, stopper[i] = j; } } } } if(stopper[i]==-2) stopper[i] = -1; if(stopper[i]!=-1) AddEdge(stopper[i], i); } void PlayGround() { cin >> n; for(int i=0; i> d >> x >> y; cows.push_back(make_pair(make_pair(x, y), d)); } for(int i=0; i