답안 #143242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143242 2019-08-13T11:55:08 Z popovicirobert Traffic (CEOI11_tra) C++14
0 / 100
1157 ms 67412 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long



/*const int MOD = ;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}*/

/*int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}*/

using namespace std;

const int MAXN = (int) 3e5;

vector <int> g[MAXN + 1], aux[MAXN + 1];
bool vis[MAXN + 1];

void go(int nod) {
    vis[nod] = 1;
    for(auto it : g[nod]) {
        if(vis[it] == 0) {
            go(it);
        }
    }
}

vector <int> top;

void topSort(int nod) {
    vis[nod] = 1;
    for(auto it : g[nod]) {
        if(vis[it] == 0) {
            topSort(it);
        }
    }
    top.push_back(nod);
}

vector <int> dag[MAXN + 1];
int idc[MAXN + 1];

void dfs(int nod, int sz) {
    idc[nod] = sz;
    vis[nod] = 1;
    for(auto it : aux[nod]) {
        if(vis[it] == 0) {
            dfs(it, sz);
        }
    }
}

int l[MAXN + 1], r[MAXN + 1];

void solve(int nod) {
    vis[nod] = 1;
    for(auto it : dag[nod]) {
        if(vis[it] == 0) {
            solve(it);
        }
        l[nod] = min(l[it], l[nod]);
        r[nod] = max(r[it], r[nod]);
    }
}

int main() {
#if 0
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, n, m, a, b;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> m >> a >> b;
    vector <int> s, d, x(n + 1), y(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
        if(x[i] == 0) s.push_back(i);
        if(x[i] == a) d.push_back(i);
    }
    for(i = 1; i <= m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        g[x].push_back(y);
        aux[y].push_back(x);
        if(z == 2) {
            g[y].push_back(x);
            aux[x].push_back(y);
        }
    }

    for(auto it : s) {
        if(vis[it] == 0)
            go(it);
    }
    sort(d.begin(), d.end(), [&](const int &a, const int &b) {
                return y[a] < y[b];
         });
    vector <int> sp(d.size());
    for(i = 0; i < d.size(); i++) {
        sp[i] = (i > 0 ? sp[i - 1] : 0) + 1 - vis[d[i]];
    }

    fill(vis + 1, vis + n + 1, 0);
    for(auto it : s) {
        if(vis[it] == 0)
            topSort(it);
    }
    fill(vis + 1, vis + n + 1, 0);
    int sz = 0;
    for(i = top.size() - 1; i >= 0; i--) {
        if(vis[top[i]] == 0)
            dfs(top[i], ++sz);
    }

    for(i = 1; i <= n; i++) {
        for(auto it : g[i]) {
            if(idc[i] != idc[it]) {
                dag[idc[i]].push_back(idc[it]);
            }
        }
    }

    fill(vis + 1, vis + n + 1, 0);
    fill(l + 1, l + n + 1, n + 1), fill(r + 1, r + n + 1, -1);
    for(i = 0; i < d.size(); i++) {
        l[idc[d[i]]] = r[idc[d[i]]] = i;
    }

    for(auto it : s) {
        if(vis[idc[it]] == 0)
            solve(idc[it]);
    }

    auto get = [&](int l, int r) {
        return sp[r] - (l > 0 ? sp[l - 1] : 0);
    };

    sort(s.begin(), s.end(), [&](const int &a, const int &b) {
                return y[a] > y[b];
         });
    for(auto nod : s) {
        int it = idc[nod];
        if(r[it] == -1) { cout << 0 << "\n"; continue; }
        cout << r[it] - l[it] + 1 - get(l[it], r[it]) << "\n";
    }

    return 0;
}

Compilation message

tra.cpp: In function 'int main()':
tra.cpp:150:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i = 0; i < d.size(); i++) {
                ~~^~~~~~~~~~
tra.cpp:176:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i = 0; i < d.size(); i++) {
                ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 21624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 21496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 21496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 21756 KB Output is correct
2 Incorrect 28 ms 22136 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 23672 KB Output is correct
2 Incorrect 99 ms 28148 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 80 ms 26400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 31292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 242 ms 33640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 345 ms 41384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 542 ms 53288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1157 ms 67412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 308 ms 44016 KB Output isn't correct
2 Halted 0 ms 0 KB -