Submission #1117300

# Submission time Handle Problem Language Result Execution time Memory
1117300 2024-11-23T09:19:48 Z manizare Traffic (CEOI11_tra) C++14
100 / 100
691 ms 85504 KB
#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define ld long double
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 3e5 + 10,  inf = 1e9+10 , mod = 998244353 ;
vector <pii>f[maxn]; 

vector <pii> si  ;
int  x[maxn] ,y[maxn] , ok[maxn] , n , a, b, m , l[maxn] ,r[maxn] , c[maxn];
bool mark[maxn] , ch[maxn] ;
vector <int> G[maxn] , tp , Gr[maxn] ;
vector <pii> cp ; 
void dfs2(int v, int p= 0){
    ch[v] = 1;
    for(int u : G[v]){
        if(mark[u] ==0)continue ;
        if(ch[u] == 0)dfs2(u) ;
        l[c[v]] = min(l[c[v]] , l[c[u]]) ;
        r[c[v]] = max(r[c[v]] , r[c[u]]) ; 
    }
}
void dfs(int v){
    mark[v] = 1;
    if(x[v] == a)ok[v] =1 ;
    for(int u  : G[v]){
        if(mark[u] == 1)continue ;
        dfs(u) ;
    }
    tp.pb(v) ;
}
int cnt= 1; 
void dfs4(int v){
    c[v] = cnt ;ch[v] = 1;
    for(int u : Gr[v]){
        if(ch[u] == 1 || mark[u] == 0)continue ;
        dfs4(u) ;
    }
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    cin >> n>> m >> a >> b ;
    vector <int> sr ;
    
    rep(i , 1, n){
        cin >> x[i] >> y[i] ;
        if(x[i] == 0){
            sr.pb(i) ;
        }
        cp.pb({y[i] , i}); 
        l[i] = inf ;
        r[i] = -inf ;
    }
    sort(all(cp));
    rep(i ,1 ,m){
        int v, u , k;
        cin >> v >> u >> k;
        Gr[u].pb(v);
        G[v].pb(u);
        if(k==2){
            G[u].pb(v) ;
            Gr[v].pb(u); 
        }
    }
    for(int x : sr){
        if(mark[x] == 0)dfs(x) ;
    }
    rep(i ,1 ,n)ch[i] =0 ;
    per(i , sz(tp)-1 , 0){
        int v =tp[i] ;
        if(ch[v] == 0){
            dfs4(v) ;
            cnt++ ;
        }
     }
     int ted= 0;
     rep(i , 0, sz(cp)-1){
        int v= cp[i].S ;
        if(ok[v] == 0)continue ;
        l[c[v]] = min(l[c[v]] , ted);
        r[c[v]] = max(r[c[v]] , ted); 
        ted ++ ;
    }
    rep(i ,1 ,n)ch[i] =0 ;
    for(int x : sr){
        if(mark[x] == 1 && ch[x] == 0)dfs2(x) ;
    }
    per(i , n-1 , 0){
        int w = cp[i].S ;
        if(x[w] != 0)continue ;
        if(l[c[w]] == inf || mark[w] == 0){
            cout << 0 << "\n";
        }else{
            cout << r[c[w]]-l[c[w]]+1<< "\n" ;
        }
    }
    return 0 ;
}
/*


*/
# Verdict Execution time Memory Grader output
1 Correct 14 ms 21584 KB Output is correct
2 Correct 14 ms 21584 KB Output is correct
3 Correct 14 ms 21756 KB Output is correct
4 Correct 17 ms 21584 KB Output is correct
5 Correct 18 ms 21512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 21584 KB Output is correct
2 Correct 14 ms 21584 KB Output is correct
3 Correct 16 ms 21584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 21584 KB Output is correct
2 Correct 16 ms 21584 KB Output is correct
3 Correct 15 ms 21616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 21840 KB Output is correct
2 Correct 21 ms 22144 KB Output is correct
3 Correct 20 ms 22096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 24016 KB Output is correct
2 Correct 48 ms 28448 KB Output is correct
3 Correct 40 ms 25036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 26896 KB Output is correct
2 Correct 67 ms 30272 KB Output is correct
3 Correct 59 ms 28016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 31428 KB Output is correct
2 Correct 99 ms 37088 KB Output is correct
3 Correct 156 ms 36804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 34564 KB Output is correct
2 Correct 95 ms 35624 KB Output is correct
3 Correct 133 ms 37316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 42176 KB Output is correct
2 Correct 170 ms 47828 KB Output is correct
3 Correct 329 ms 50880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 54212 KB Output is correct
2 Correct 308 ms 62284 KB Output is correct
3 Correct 326 ms 52928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 633 ms 73000 KB Output is correct
2 Correct 376 ms 64240 KB Output is correct
3 Correct 640 ms 71348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 45676 KB Output is correct
2 Correct 361 ms 71336 KB Output is correct
3 Correct 534 ms 65972 KB Output is correct
4 Correct 691 ms 85504 KB Output is correct