제출 #975726

#제출 시각아이디문제언어결과실행 시간메모리
975726oviyan_gandhi다리 (APIO19_bridges)C++14
73 / 100
3073 ms22084 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> pii; #define N 50001 #define M 100001 int lnk[N], sz[N]; inline void build(int n){ fill(sz, sz+n+1, 1); iota(lnk, lnk+n+1, 0); } inline int root(int x){ int l = x; while (lnk[l] != l) l = lnk[l]; return lnk[x] = l; } inline void unite(int x, int y){ x = root(x), y = root(y); if (x == y) return; if (sz[x] < sz[y]) swap(x, y); sz[x] += sz[y]; lnk[y] = x; } struct Edge { int a, b, w, i; bool operator < (const Edge &o) const { return make_pair(w, i) > make_pair(o.w, o.i); } } edges[M], queries[M], sorted_qu[M]; vector<int> adj[N]; bool vis[N]; int ans[M]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 1; i <= m; i++){ cin >> edges[i].a >> edges[i].b >> edges[i].w; edges[i].i = i; } int q; cin >> q; for (int i = 1; i <= q; i++){ cin >> queries[i].a >> queries[i].b >> queries[i].w; queries[i].i = i; sorted_qu[i] = queries[i]; } set<Edge> sorted; for (int i = 1; i <= m; i++) sorted.insert(edges[i]); int bsz = ceil(sqrt(q)); for (int s = 1; s <= q; s += bsz){ build(n); map<int, int> changed; for (int i = s; i < min(q+1, s+bsz); i++) if (queries[i].a == 1) changed[queries[i].b] = edges[queries[i].b].w; sort(sorted_qu+s, sorted_qu+min(s+bsz, q+1)); auto it = sorted.begin(); for (int qi = s; qi < min(s+bsz, q+1); qi++){ if (sorted_qu[qi].a == 1) continue; auto [_, start, w, idx] = sorted_qu[qi]; for (; it != sorted.end() && it->w >= w; it++) if (!changed.count(it->i)) unite(it->a, it->b); map<int, int> curr(changed); for (int i = s; i < idx; i++) if (queries[i].a == 1) curr[queries[i].b] = queries[i].w; vector<int> graph; for (auto [ei, ew] : curr){ if (ew >= w && root(edges[ei].a) != root(edges[ei].b)){ adj[root(edges[ei].a)].push_back(root(edges[ei].b)); adj[root(edges[ei].b)].push_back(root(edges[ei].a)); graph.push_back(root(edges[ei].a)); graph.push_back(root(edges[ei].b)); } } queue<int> q; q.push(root(start)); vis[root(start)] = true; graph.push_back(root(start)); while (!q.empty()){ int u = q.front(); q.pop(); ans[idx] += sz[u]; for (int v : adj[u]){ if (!vis[v]){ vis[v] = true; q.push(v); } } } for (int i : graph){ vis[i] = false; adj[i].clear(); } } for (int i = s; i < min(q+1, s+bsz); i++) if (queries[i].a == 1) changed[queries[i].b] = queries[i].w; for (auto [i, w] : changed){ sorted.erase(edges[i]); edges[i].w = w; sorted.insert(edges[i]); } } for (int i = 1; i <= q; i++) if (ans[i]) cout << ans[i] << '\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp: In function 'int32_t main()':
bridges.cpp:67:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   67 |             auto [_, start, w, idx] = sorted_qu[qi];
      |                  ^
bridges.cpp:76:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   76 |             for (auto [ei, ew] : curr){
      |                       ^
bridges.cpp:110:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  110 |         for (auto [i, w] : changed){
      |                   ^
#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...