#include <bits/stdc++.h>
#define DIM 300010
#define DIMBUFF 10000000
#define INF 2000000000
using namespace std;
vector <int> L[DIM],inv[DIM],est,vest;
vector <pair<int,int> > d;
int f[DIM],viz[DIM],sol[DIM],dr[DIM],st[DIM];
pair <int,int> pct[DIM];
deque <int> c;
int n,m,a,b,x,y,i,j,val,maxi,mini,poz,ok,pos;
char buff[DIMBUFF];
int get_nr(){
while (!(buff[pos] >= '0' && buff[pos] <= '9'))
pos++;
int nr = 0;
while (buff[pos] >= '0' && buff[pos] <= '9'){
nr = nr * 10 + buff[pos] - '0';
pos++;
}
return nr;
}
void dfs (int nod){
viz[nod] = 1;
if (f[nod] == 2){
if (pct[nod].second > maxi)
maxi = pct[nod].second, poz = nod;
}
for (auto vecin : L[nod]){
if (!viz[vecin])
dfs (vecin);
}
}
void dfs2 (int nod){
viz[nod] = val;
if (f[nod] == 2){
if (pct[nod].second < mini)
mini = pct[nod].second, poz = nod;
}
for (auto vecin : L[nod]){
if (!viz[vecin])
dfs2 (vecin);
}
}
inline int cmp (int a, int b){
return pct[a].second < pct[b].second;
}
int cautare_binara (vector<int> v, int x){
int st = 0, dr = v.size()-1;
while (st <= dr){
int mid = (st+dr)>>1;
if (pct[v[mid]].second == pct[x].second)
return mid;
if (pct[v[mid]].second < pct[x].second)
st = mid+1;
else dr = mid-1;
}
}
int main (){
//FILE *fin = fopen ("date.in","r");
//FILE *fout = fopen ("date.out","w");
FILE *fin = stdin;
FILE *fout = stdout;
fread (buff,1,DIMBUFF,fin);
n = get_nr(), m = get_nr(), a = get_nr(), b = get_nr();
//cin>>n>>m>>a>>b;
for (i=1;i<=n;i++){
//cin>>pct[i].first>>pct[i].second;
pct[i].first = get_nr(), pct[i].second = get_nr();
if (pct[i].first == 0)
f[i] = 1; /// vest
if (pct[i].first == a)
f[i] = 2; /// est
}
for (i=1;i<=m;i++){
//cin>>x>>y>>val;
x = get_nr(), y = get_nr(), val = get_nr();
L[x].push_back(y);
inv[y].push_back(x);
if (val == 2){
L[y].push_back(x);
inv[x].push_back(y);
}
}
/// pastrez doar nodurile din dreapta care sunt reachable din stanga
for (i=1;i<=n;i++)
if (f[i] == 1){
c.push_back(i);
viz[i] = 1;
}
while (!c.empty()){
int nod = c.front();
c.pop_front();
for (auto vecin : L[nod]){
if (!viz[vecin]){
viz[vecin] = 1;
c.push_back(vecin);
}}}
for (i=1;i<=n;i++)
if (f[i] == 2 && viz[i])
est.push_back(i);
/// pastrez in stanga doar nodurile care conteaza si din care pot sa ajung in dr
c.clear();
memset (viz,0,sizeof viz);
for (i=1;i<=n;i++)
if (f[i] == 2){
c.push_back(i);
viz[i] = 1;
}
while (!c.empty()){
int nod = c.front();
c.pop_front();
for (auto vecin : inv[nod]){
if (!viz[vecin]){
viz[vecin] = 1;
c.push_back(vecin);
}}}
for (i=1;i<=n;i++)
if (f[i] == 1 && viz[i])
vest.push_back(i);
sort (vest.begin(),vest.end(),cmp);
memset (viz,0,sizeof viz);
for (int i=0;i<vest.size();i++){
maxi = -INF, poz = 0;
dfs (vest[i]);
if (poz)
dr[i] = poz;
else dr[i] = dr[i-1];
}
memset (viz,0,sizeof viz);
for (int i=vest.size()-1;i>=0;i--){
mini = INF, poz = 0;
dfs2 (vest[i]);
if (poz)
st[i] = poz;
else st[i] = st[i+1];
}
sort (est.begin(),est.end(),cmp);
for (i=0;i<vest.size();i++)
sol[vest[i]] = cautare_binara (est,dr[i]) - cautare_binara (est,st[i]) + 1;
for (i=1;i<=n;i++)
if (f[i] == 1)
d.push_back(make_pair(pct[i].second,sol[i]));
sort (d.begin(),d.end());
reverse(d.begin(),d.end());
for (auto it : d)
fprintf(fout,"%d\n",it.second);
//cout<<it.second<<"\n";
return 0;
}
Compilation message
tra.cpp: In function 'int main()':
tra.cpp:147:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
147 | for (int i=0;i<vest.size();i++){
| ~^~~~~~~~~~~~
tra.cpp:167:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
167 | for (i=0;i<vest.size();i++)
| ~^~~~~~~~~~~~
tra.cpp: In function 'int cautare_binara(std::vector<int>, int)':
tra.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
66 | }
| ^
tra.cpp: In function 'int main()':
tra.cpp:76:11: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | fread (buff,1,DIMBUFF,fin);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15564 KB |
Output is correct |
2 |
Correct |
10 ms |
15564 KB |
Output is correct |
3 |
Correct |
9 ms |
15564 KB |
Output is correct |
4 |
Correct |
9 ms |
15564 KB |
Output is correct |
5 |
Correct |
9 ms |
15564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15552 KB |
Output is correct |
2 |
Correct |
9 ms |
15596 KB |
Output is correct |
3 |
Correct |
10 ms |
15548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15536 KB |
Output is correct |
2 |
Correct |
9 ms |
15664 KB |
Output is correct |
3 |
Correct |
10 ms |
15564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
15676 KB |
Output is correct |
2 |
Correct |
12 ms |
16164 KB |
Output is correct |
3 |
Correct |
11 ms |
15964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
17100 KB |
Output is correct |
2 |
Correct |
137 ms |
21252 KB |
Output is correct |
3 |
Correct |
24 ms |
18248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
19576 KB |
Output is correct |
2 |
Correct |
181 ms |
22876 KB |
Output is correct |
3 |
Correct |
50 ms |
20548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
23344 KB |
Output is correct |
2 |
Correct |
455 ms |
27888 KB |
Output is correct |
3 |
Correct |
175 ms |
28092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
26204 KB |
Output is correct |
2 |
Correct |
338 ms |
27632 KB |
Output is correct |
3 |
Correct |
178 ms |
28696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
32072 KB |
Output is correct |
2 |
Correct |
3557 ms |
36356 KB |
Output is correct |
3 |
Correct |
387 ms |
39780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
296 ms |
41512 KB |
Output is correct |
2 |
Incorrect |
406 ms |
45664 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
281 ms |
90956 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
33640 KB |
Output is correct |
2 |
Incorrect |
680 ms |
46676 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |