Submission #996369

# Submission time Handle Problem Language Result Execution time Memory
996369 2024-06-10T14:05:04 Z cadmiumsky Reconstruction Project (JOI22_reconstruction) C++17
3 / 100
5000 ms 1048576 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int mmax = 1e5 + 5;

vector<tii> scand[mmax]; 

struct DSU {
   vector<int> dsu;
   int cost;
   void init(int n) {
      dsu.assign(n, 0);
      cost = 0;
      iota(all(dsu), 0);
   }
   int f(int x) { return dsu[x] == x? x : dsu[x] = f(dsu[x]); }
   bool unite(int w, int x, int y) {
      x = f(x);
      y = f(y);
      if(x == y) return 0;
      dsu[x] = y;
      cost += w;
      return 1;
   }
   bool unite(tii a) {
      return unite(get<0>(a), get<1>(a), get<2>(a));
   }
};

signed main() {
   cin.tie(0) -> sync_with_stdio(0);
   int n, m;
   cin >> n >> m;
   
   map<int, int> fpozc;
   vector<tii> edges(m);
   for(auto &[w, x, y] : edges) cin >> x >> y >> w, --x, --y;
   
   sort(all(edges));
   
   auto addTo = [&](tii a, vector<tii>& nv, vector<tii> R) {
      R.insert(R.begin(), a);
      DSU d;
      d.init(n);
      nv.clear();
      for(auto t : R)
         if(d.unite(t)) nv.emplace_back(t); 
   };
   
   for(int i = m - 1; i >= 0; i--) {
      addTo(edges[i], scand[i], scand[i + 1]);
   }
   
   vector<tii> pref;
   int q, p = 0;
   cin >> q;
   for(int i = 0; i < q; i++) {
      int X;
      cin >> X;
      while(p < m && get<0>(edges[p]) <= X)
         addTo(edges[p], pref, pref),
         p++;
      vector<tii> L, R, mine;
      for(auto [w, x, y] : pref) L.emplace_back(X - w, x, y);
      for(auto [w, x, y] : scand[p]) R.emplace_back(w - X, x, y);
      merge(all(L), all(R), back_inserter(mine));
      DSU d;
      d.init(n);
      for(auto x : mine)
         d.unite(x);
      cout << d.cost << '\n';
      
   }
}

/**
      Istenem! Nu poate fi real.
-- Surse verificate
*/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 0 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 0 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Runtime error 1059 ms 1048576 KB Execution killed with signal 9
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Runtime error 868 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 0 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Execution timed out 5086 ms 25464 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 0 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Runtime error 1059 ms 1048576 KB Execution killed with signal 9
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 0 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Runtime error 1059 ms 1048576 KB Execution killed with signal 9
21 Halted 0 ms 0 KB -