Submission #996974

#TimeUsernameProblemLanguageResultExecution timeMemory
996974SN0WM4NBridges (APIO19_bridges)C++14
14 / 100
62 ms8072 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define sort undefined_function // To use stable_sort instead sort #define bpc __builtin_popcount #define ull unsigned long long #define ld double #define ll long long #define mp make_pair #define F first #define S second #pragma GCC optimize("O3") #ifdef LOCAL #include "debug.h" #else #define dbg(...) 0 #endif using namespace __gnu_pbds; using namespace std; typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> Tree; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll INF = 9223372036854775807LL; const ll inf = 2147483647; const ll MOD = 1e9 + 7; //[998244353, 1e9 + 7, 1e9 + 13] const ld PI = acos(-1); const ll NROOT = 500; ll binpow(ll a, ll b, ll _MOD = -1) { if (_MOD == -1) _MOD = MOD; ll res = 1; for (; b; b /= 2, a *= a, a %= _MOD) if (b & 1) res *= a, res %= _MOD; return res; } void set_IO(string s) { #ifndef LOCAL string in = s + ".in"; string out = s + ".out"; freopen(in.c_str(), "r", stdin); freopen(out.c_str(), "w", stdout); #endif } bool dataOverflow(ll a, ll b) {return (log10(a) + log10(b) >= 18);} ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} ll lcm(ll a, ll b) {return a * b / gcd(a, b);} ll ceil(ll a, ll b) {return (a + b - 1) / b;} ll invmod(ll a) {return binpow(a, MOD - 2);} class DSU{ private: int n; vector<int> uf, sz; public: DSU(int _n) { n = _n; uf.resize(n + 1, -1); sz.resize(n + 1, 1); } int uf_find(int x) { return uf[x] == -1 ? x : uf[x] = uf_find(uf[x]); } bool uf_join(int x, int y) { x = uf_find(x); y = uf_find(y); if (x == y) return 0; uf[y] = x; sz[x] += sz[y]; sz[y] = 0; return 1; } int get_size(int x) { return sz[uf_find(x)]; } }; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m; vector<pair<int, pair<int, int>>> edges; for (int i= 1; i <= m; i ++) { int a, b, c; cin >> a >> b >> c; edges.push_back({c, {a, b}}); } cin >> q; vector<pair<int, pair<int, int>>> qr; for (int i = 1; i <= q; i ++) { int tq, a, b; cin >> tq >> a >> b; if (tq == 1) exit(1); qr.push_back({b, {a, i}}); } stable_sort(edges.rbegin(), edges.rend()); stable_sort(qr.rbegin(), qr.rend()); vector<int> ans(q + 1); DSU aux(n + 1); int i = 0; for (auto &x : qr) { int w = x.F; auto [s, index] = x.S; dbg(w, s, index); while (i < edges.size() && edges[i].F >= w) { auto [a, b] = edges[i].S; aux.uf_join(a, b); i ++; } ans[index] = aux.get_size(s); } for (int i = 1; i <= q; i ++) cout << ans[i] << "\n"; return 0; }

Compilation message (stderr)

bridges.cpp: In function 'int32_t main()':
bridges.cpp:126:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  126 |   auto [s, index] = x.S;
      |        ^
bridges.cpp:18:19: warning: statement has no effect [-Wunused-value]
   18 |  #define dbg(...) 0
      |                   ^
bridges.cpp:128:3: note: in expansion of macro 'dbg'
  128 |   dbg(w, s, index);
      |   ^~~
bridges.cpp:130:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |   while (i < edges.size() && edges[i].F >= w) {
      |          ~~^~~~~~~~~~~~~~
bridges.cpp:131:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  131 |    auto [a, b] = edges[i].S;
      |         ^
bridges.cpp: In function 'void set_IO(std::string)':
bridges.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  freopen(in.c_str(),  "r",  stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:48:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  freopen(out.c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...