# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1110528 |
2024-11-09T19:08:05 Z |
vjudge1 |
Traffic (CEOI11_tra) |
C++17 |
|
290 ms |
28748 KB |
#include "bits/stdc++.h"
#define ll long long
using namespace std;
const int N=2e5+1,mod=1e9+7;
vector<int>l,r;
vector<vector<int>>v(N),rev(N);
int n,m,A,B;
int x[N],y[N];
bool vis[N],removed[N];
void dfs(int idx){
vis[idx]=1;
for(auto i:v[idx])
if(!vis[i] && !removed[i])
dfs(i);
}
void del(int idx){
vis[idx]=1;
for(auto i:v[idx])
if(!vis[i])
del(i);
}
void delr(int idx){
vis[idx]=1;
for(auto i:rev[idx])
if(!vis[i])
delr(i);
}
int mx[N],mn[N];
int main(){
cin>>n>>m>>A>>B;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
if(x[i]==0)
l.push_back(i);
if(x[i]==A)
r.push_back(i);
}
//reverse(l.begin(),l.end());
while(m--){
int d,c,k;
cin>>c>>d>>k;
v[c].push_back(d);
rev[d].push_back(c);
if(k==2){
v[d].push_back(c);
rev[c].push_back(d);
}
}
for(auto i:l)
del(i);
for(int i=1;i<=n;i++)
if(!vis[i])
removed[i]=1;
memset(vis,0,sizeof vis);
for(auto i:r)
delr(i);
for(int i=1;i<=n;i++)
if(!vis[i])
removed[i]=1;
for(int i=0;i<r.size();i++)
if(removed[r[i]])
r.erase(r.begin()+i);
memset(vis,0,sizeof vis);
int idx=0;
for(int i=0;i<l.size();i++){
if(removed[l[i]])continue;
dfs(l[i]);
while(idx+1<r.size() && vis[r[idx+1]])
idx++;
mx[i]=idx;
}
memset(vis,0,sizeof vis);
idx=r.size()-1;
for(int i=l.size()-1;i>=0;i--){
if(removed[l[i]])continue;
dfs(l[i]);
while(idx-1>=0 && vis[r[idx-1]])
idx--;
mn[i]=idx;
}
vector<int>ans;
for(int i=0;i<l.size();i++){
if(removed[l[i]]) ans.push_back(0);
else ans.push_back(mx[i]-mn[i]+1);
}
reverse(ans.begin(),ans.end());
for(auto i:ans)cout<<i<<'\n';
return 0;
}
Compilation message
tra.cpp: In function 'int main()':
tra.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0;i<r.size();i++)
| ~^~~~~~~~~
tra.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<l.size();i++){
| ~^~~~~~~~~
tra.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | while(idx+1<r.size() && vis[r[idx+1]])
| ~~~~~^~~~~~~~~
tra.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int i=0;i<l.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
11856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
11856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
11856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
11856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
12368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
14156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
124 ms |
17784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
168 ms |
17932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
290 ms |
25416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
112 ms |
26440 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
127 ms |
28748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
115 ms |
26580 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |