#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pp pair<int, int>
#define F first
#define S second
struct point{
int x, y, ix;
};
const int N = 3 * 1e5 + 100;
int n, m, A, B; vector<point> pt;
vector<int> g[N], tg[N], graph[N], order;
int new_idx[N], root[N], used[N], l[N], r[N];
int w[N], pref[N];
bool cmp(point x, point y){
if (x.x != y.x)
return (x.x < y.x);
return (x.y > y.y);
}
void dfs1(int x){
used[x] = 1;
for (int y: g[x]){
if (!used[y]) dfs1(y);
}
order.pb(x);
}
int cnt = 0;
void dfs2(int x){
used[x] = 1;
for (int y: tg[x]){
if (!used[y]) dfs2(y);
}
root[x] = cnt;
if (pt[x].x == A){
l[cnt] = min(l[cnt], x);
r[cnt] = max(r[cnt], x);
}
}
void dfs3(int x){
used[x] = 1;
for (int y: graph[x]){
if (!used[y]) dfs3(y);
l[x] = min(l[x], l[y]);
r[x] = max(r[x], r[y]);
}
//cout << ": " << x << ' ' << l[x] << ' ' << r[x] << endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> A >> B;
pt.resize(n); int k = 1;
for (int i = 0; i < n; ++i){
cin >> pt[i].x >> pt[i].y;
pt[i].ix = i;
}
sort(pt.begin(), pt.end(), cmp);
for (auto i = 0; i < n; ++i){
new_idx[pt[i].ix] = i;
l[i] = N; r[i] = -1;
if (pt[i].x == A) ++w[i];
}
for (int i = 0; i < m; ++i){
int u, v, t; cin >> u >> v >> t;
--u; --v; u = new_idx[u]; v = new_idx[v];
g[u].pb(v); tg[v].pb(u);
if (t == 2){
g[v].pb(u); tg[u].pb(v);
}
}
while (k < n && pt[k].x == 0) ++k;
for (int i = 0; i < k; ++i){
if (!used[i]) dfs1(i);
}
for (int i = 0; i < n; ++i){
if (pt[i].x == A && !used[i]) --w[i];
}
memset(used, 0, sizeof(used));
/*cout << "-----------------------------" << endl;
for (auto x: pt) cout << x.x << ' ' << x.y << ' ' << x.ix << endl;
for (int x: order) cout << x << ' ';
cout << endl;*/
reverse(order.begin(), order.end());
for (int x: order){
if (!used[x]){
dfs2(x); ++cnt;
}
}
/*for (int i = 0; i < n; ++i)
cout << root[i] << ' ';
cout << endl;*/
for (int i = 0; i < n; ++i){
for (int x: g[i]) graph[root[i]].pb(root[x]);
}
memset(used, 0, sizeof(used));
for (int i = 0; i < cnt; ++i){
if (!used[i]) dfs3(i);
}
/*for (int i = 0; i < n; ++i)
cout << l[i] << ' ' << r[i] << endl;*/
pref[0] = w[0];
for (int i = 1; i < n; ++i)
pref[i] = w[i] + pref[i - 1];
for (int i = 0; i < k; ++i){
int x = root[i];
cout << (pref[r[x]] - pref[l[x] - 1]) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
22612 KB |
Output is correct |
2 |
Correct |
11 ms |
22612 KB |
Output is correct |
3 |
Correct |
11 ms |
22612 KB |
Output is correct |
4 |
Correct |
12 ms |
22612 KB |
Output is correct |
5 |
Correct |
14 ms |
22612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
22612 KB |
Output is correct |
2 |
Correct |
12 ms |
22648 KB |
Output is correct |
3 |
Correct |
12 ms |
22612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
22612 KB |
Output is correct |
2 |
Correct |
12 ms |
22768 KB |
Output is correct |
3 |
Correct |
13 ms |
22720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
22868 KB |
Output is correct |
2 |
Correct |
15 ms |
23380 KB |
Output is correct |
3 |
Correct |
16 ms |
23224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
24700 KB |
Output is correct |
2 |
Correct |
67 ms |
29920 KB |
Output is correct |
3 |
Correct |
42 ms |
26436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
27044 KB |
Output is correct |
2 |
Correct |
87 ms |
32324 KB |
Output is correct |
3 |
Correct |
63 ms |
30084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
31268 KB |
Output is correct |
2 |
Correct |
155 ms |
39312 KB |
Output is correct |
3 |
Correct |
187 ms |
39136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
33308 KB |
Output is correct |
2 |
Correct |
152 ms |
38956 KB |
Output is correct |
3 |
Correct |
247 ms |
39904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
39384 KB |
Output is correct |
2 |
Correct |
243 ms |
50276 KB |
Output is correct |
3 |
Correct |
475 ms |
54804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
378 ms |
49532 KB |
Output is correct |
2 |
Correct |
422 ms |
67204 KB |
Output is correct |
3 |
Correct |
440 ms |
57808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
888 ms |
63072 KB |
Output is correct |
2 |
Correct |
419 ms |
69648 KB |
Output is correct |
3 |
Correct |
858 ms |
76024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
214 ms |
41068 KB |
Output is correct |
2 |
Correct |
545 ms |
74596 KB |
Output is correct |
3 |
Correct |
667 ms |
72020 KB |
Output is correct |
4 |
Correct |
949 ms |
88800 KB |
Output is correct |