Submission #602402

# Submission time Handle Problem Language Result Execution time Memory
602402 2022-07-23T03:49:10 Z verngutz Aesthetic (NOI20_aesthetic) C++17
16 / 100
357 ms 59124 KB
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
struct edge {
    int u, v;
    edge reverse() const { return {v, u}; }
    friend ostream& operator<<(ostream& os, const edge& e) {
        return os << "{u: " << e.u << ", v: " << e.v << "}";
    }
};
template <bool Directed, typename TEdge, bool Index> struct graph {
    using EType = TEdge;
    vector<TEdge> edges;
    vector<vector<int>> adj;
    graph(int n) : adj(n + Index) {}
    graph(int n, int m) : graph(n) { edges.reserve(m << not Directed); }
    TEdge& operator()(int e) { return edges[e]; }
    vector<int>& operator[](int u) { return adj[u]; }
    int size() { return adj.size() - Index; }
    void append(int u, const TEdge& e) {
        adj[u].push_back(edges.size());
        edges.push_back(e);
    }
    void add_edge(const TEdge& e) {
        append(e.u, e);
        if(not Directed) append(e.v, e.reverse());
    }
};
template <typename TEdge, bool Index> pair<vector<int>, vector<vector<int>>> find_2eccs(graph<0, TEdge, Index>& g) {
    vector<int> vis(g.adj.size()), low(g.adj.size()), cut_edge(g.edges.size()), s;
    vector<vector<int>> _2eccs = {};
    int timer = 1;
    function<void(int, int)> dfs = [&](int u, int from) {
        vis[u] = low[u] = timer++;
        s.push_back(u);
        for(int e : g[u]) {
            if(not vis[g(e).v]) {
                dfs(g(e).v, e & ~1);
                if(vis[u] < low[g(e).v]) {
                    cut_edge[e] = cut_edge[e ^ 1] = true;
                    _2eccs.push_back(vector<int>());
                    do {
                        _2eccs.back().push_back(s.back()), s.pop_back();
                    } while(_2eccs.back().back() != g(e).v);
                }
                low[u] = min(low[u], low[g(e).v]);
            } else if((e & ~1) != from and vis[u] > vis[g(e).v]) {
                low[u] = min(low[u], vis[g(e).v]);
            }
        }
    };
    for(int u = Index; u < g.adj.size(); u++) if(not vis[u]) {
        dfs(u, -1);
        _2eccs.push_back(vector<int>());
        while(not s.empty()) {
            _2eccs.back().push_back(s.back()), s.pop_back();
        }
    }
    return {move(cut_edge), move(_2eccs)};
}
template <bool Directed, typename TEdge, bool Index>
pair<vector<int>, vector<int>> bfs(graph<Directed, TEdge, Index>& g, const vector<int>& s) {
    vector<int> d(g.adj.size(), lim<int>::max()), p(g.adj.size(), -1);
    queue<int> q;
    for(int u : s) {
        d[u] = 0;
        q.push(u);
    }
    while(not q.empty()) {
        int u = q.front(); q.pop();
        for(int e : g[u]) {
            if(d[g(e).v] > d[u] + 1) {
                d[g(e).v] = d[u] + 1, p[g(e).v] = e;
                q.push(g(e).v);
            }
        }
    }
    return {move(d), move(p)};
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    graph<0, edge, 1> g(n, m);
    edge last_edge;
    for(int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        g.add_edge(last_edge = {min(u, v), max(u, v)});
    }
    graph<0, edge, 1> sp_dag(n);
    auto [ds, ps] = bfs(g, {1});
    auto [dt, pt] = bfs(g, {n});
    for(auto [u, v] : g.edges) {
        if(ds[u] + 1 + dt[v] == ds[n]) {
            sp_dag.add_edge({min(u, v), max(u, v)});
        }
    }
    auto [cut_edge, _2eccs] = find_2eccs(sp_dag);
    bool increase = false;
    for(int i = 0; i < sp_dag.edges.size(); i += 2) {
        edge& sp_edge = sp_dag.edges[i];
        increase |= cut_edge[i] and (sp_edge.u != last_edge.u or sp_edge.v != last_edge.v);
    }
    cout << ds[n] + increase << endl;
    return 0;
}

Compilation message

Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge, std::allocator<edge> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for(int i = 0; i < sp_dag.edges.size(); i += 2) {
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
Aesthetic.cpp: In instantiation of 'std::pair<std::vector<int>, std::vector<std::vector<int> > > find_2eccs(graph<false, TEdge, Index>&) [with TEdge = edge; bool Index = true]':
Aesthetic.cpp:108:48:   required from here
Aesthetic.cpp:60:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int u = Index; u < g.adj.size(); u++) if(not vis[u]) {
      |                        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 348 ms 55412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 357 ms 56244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 252 ms 37868 KB Output is correct
2 Correct 154 ms 50532 KB Output is correct
3 Correct 221 ms 45152 KB Output is correct
4 Correct 232 ms 45132 KB Output is correct
5 Correct 228 ms 45104 KB Output is correct
6 Correct 219 ms 45228 KB Output is correct
7 Correct 253 ms 45324 KB Output is correct
8 Correct 225 ms 45408 KB Output is correct
9 Correct 221 ms 45068 KB Output is correct
10 Correct 257 ms 45652 KB Output is correct
11 Correct 215 ms 45480 KB Output is correct
12 Correct 245 ms 41456 KB Output is correct
13 Correct 214 ms 45572 KB Output is correct
14 Correct 132 ms 59124 KB Output is correct
15 Correct 129 ms 59076 KB Output is correct
16 Correct 239 ms 40748 KB Output is correct
17 Correct 233 ms 39660 KB Output is correct
18 Correct 245 ms 40464 KB Output is correct
19 Correct 147 ms 50748 KB Output is correct
20 Correct 151 ms 50776 KB Output is correct
21 Correct 151 ms 50784 KB Output is correct
22 Correct 148 ms 50756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 37868 KB Output is correct
2 Correct 154 ms 50532 KB Output is correct
3 Correct 221 ms 45152 KB Output is correct
4 Correct 232 ms 45132 KB Output is correct
5 Correct 228 ms 45104 KB Output is correct
6 Correct 219 ms 45228 KB Output is correct
7 Correct 253 ms 45324 KB Output is correct
8 Correct 225 ms 45408 KB Output is correct
9 Correct 221 ms 45068 KB Output is correct
10 Correct 257 ms 45652 KB Output is correct
11 Correct 215 ms 45480 KB Output is correct
12 Correct 245 ms 41456 KB Output is correct
13 Correct 214 ms 45572 KB Output is correct
14 Correct 132 ms 59124 KB Output is correct
15 Correct 129 ms 59076 KB Output is correct
16 Correct 239 ms 40748 KB Output is correct
17 Correct 233 ms 39660 KB Output is correct
18 Correct 245 ms 40464 KB Output is correct
19 Correct 147 ms 50748 KB Output is correct
20 Correct 151 ms 50776 KB Output is correct
21 Correct 151 ms 50784 KB Output is correct
22 Correct 148 ms 50756 KB Output is correct
23 Incorrect 250 ms 41756 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -