#include <bits/stdc++.h>
using namespace std;
const int INF = 2'000'000'000;
const int MXN = 300'000;
vector<int> g[MXN];
int X[MXN], Y[MXN], ord[MXN], D[2][MXN];
vector<int> pref, west, east;
vector<bool> vis(MXN);
void dfs(int node){
if(vis[node])
return;
vis[node] = 1;
if(ord[node] != -1){
D[0][node] = min(D[0][node], ord[node]);
D[1][node] = max(D[1][node], ord[node]);
}
for(int v : g[node]){
dfs(v);
}
for(int v : g[node]){
D[0][node] = min(D[0][node], D[0][v]);
D[1][node] = max(D[1][node], D[1][v]);
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M, A, B;
cin >> N >> M >> A >> B;
memset(ord, -1, sizeof ord);
memset(D[1], -1, sizeof D[1]);
for(int i = 0; i < N; i++)
D[0][i] = INF;
for(int i = 0; i < N; i++){
cin >> X[i] >> Y[i];
if(X[i] == 0) west.push_back(i);
else if (X[i] == A) east.push_back(i);
}
for(int i = 0; i < M; i++){
int u, v, k;
cin >> u >> v >> k;
--u, --v;
g[u].push_back(v);
if(k == 2) g[v].push_back(u);
}
sort(west.begin(), west.end(), [&](int i, int j){
return Y[i] > Y[j];
});
sort(east.begin(), east.end(), [&](int i, int j){
return Y[i] < Y[j];
});
for(int i = 0; i < east.size(); i++)
ord[east[i]] = i;
reverse(west.begin(), west.end());
for(int v : west){
dfs(v);
}
int x = east.size();
pref.resize(x+1);
for(int i = 1; i <= x; i++)
pref[i] = pref[i-1] + vis[east[i-1]];
fill(vis.begin(), vis.end(), 0);
for(int v : west)
dfs(v);
fill(vis.begin(), vis.end(), 0);
reverse(west.begin(), west.end());
for(int v : west)
dfs(v);
for(int v : west){
if(D[1][v] == -1){
cout << 0 << '\n';
continue;
}
cout << pref[D[1][v]+1] - pref[D[0][v]] << '\n';
}
return 0;
}
Compilation message
tra.cpp: In function 'int32_t main()':
tra.cpp:69:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i = 0; i < east.size(); i++)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9676 KB |
Output is correct |
2 |
Correct |
7 ms |
9676 KB |
Output is correct |
3 |
Correct |
7 ms |
9760 KB |
Output is correct |
4 |
Correct |
8 ms |
9680 KB |
Output is correct |
5 |
Correct |
8 ms |
9764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9700 KB |
Output is correct |
2 |
Correct |
9 ms |
9676 KB |
Output is correct |
3 |
Correct |
8 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9676 KB |
Output is correct |
2 |
Correct |
8 ms |
9688 KB |
Output is correct |
3 |
Correct |
7 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9804 KB |
Output is correct |
2 |
Incorrect |
11 ms |
9932 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
10520 KB |
Output is correct |
2 |
Incorrect |
48 ms |
12176 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
11332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
77 ms |
12692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
115 ms |
13604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
203 ms |
15660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
348 ms |
19192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
752 ms |
24964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
183 ms |
16328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |