Submission #447906

# Submission time Handle Problem Language Result Execution time Memory
447906 2021-07-28T06:47:02 Z zxcvbnm Traffic (CEOI11_tra) C++14
32 / 100
86 ms 11836 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int nax = 6005;
#define x first
#define y second
int n, m, a, b;
vector<int> adj[nax];
vector<pair<int, int>> p;
vector<int> from, to;
int bfs(int s) {
    vector<bool> vis(n+1, false);
    queue<int> q;
    q.push(s);
    vis[s] = true;

    while(!q.empty()) {
        int v = q.front();
        q.pop();

        for(int u : adj[v]) {
            if (!vis[u]) {
                q.push(u);
                vis[u] = true;
            }
        }
    }

    int cnt = 0;
    for(int i : to) {
        if (vis[i]) {
            cnt++;
        }
    }
    return cnt;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> a >> b;
    p.resize(n);
    for(int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
        if (p[i].x == 0) {
            from.push_back(i);
        } else if (p[i].x == a) {
            to.push_back(i);
        }
    }

    for(int i = 0; i < m; i++) {
        int v1, v2, type;
        cin >> v1 >> v2 >> type;
        v1--, v2--;
        adj[v1].push_back(v2);
        if (type == 2) {
            adj[v2].push_back(v1);
        }
    }

    sort(from.begin(), from.end(), [&](const int& left, const int& right) {
        return p[left].y > p[right].y;
    });

    vector<int> ans;
    for(int i : from) {
        ans.push_back(bfs(i));
//        cout << i << " " << ans.back() << "\n";
    }

    for(int i : ans) {
        cout << i << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 71 ms 720 KB Output is correct
3 Correct 7 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 1820 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 2252 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 3800 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 3932 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 48 ms 6744 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 80 ms 10920 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 79 ms 11564 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 11836 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -