이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 5e4 + 5;
const int BLOCK = 500;
const double eps = 1e-9;
int n, m, q, vis[MAXN];
int par[MAXN], sz[MAXN], ans[2*MAXN];
int U[2*MAXN], V[2*MAXN], W[2*MAXN], st[2*MAXN];
vector<array<int,4>> arr;
vector<array<int,3>> qry;
vi adj[MAXN];
int qryD(int x) { return par[x] == x ? x : par[x] = qryD(par[x]); }
void join(int u, int v) {
u = qryD(u), v = qryD(v);
if (u == v) return;
if (sz[u] > sz[v]) swap(u,v);
par[u] = v;
sz[v] += sz[u];
}
int cnt = 0;
void dfs(int u, int& ret) {
vis[u] = cnt;
ret += sz[u];
for (int v: adj[u])
if (vis[v] != cnt)
dfs(v, ret);
}
void solve(int lo, int hi) {
for (int i = 0; i <= n; i++) par[i] = i, sz[i] = 1;
vector<array<int,3>> cur, nx;
while (!qry.empty() && qry.back()[1] <= hi) {
cur.pb(qry.back()); qry.pop_back();
}
sort(cur.begin(),cur.end());
int ind = 0;
while (!cur.empty()) {
int w, i, s; w = cur.back()[0], i = cur.back()[1], s = cur.back()[2];
cur.pop_back();
for (; ind < arr.size() && w <= arr[ind][0]; ind++) {
if (hi < arr[ind][2] || arr[ind][3] < lo) continue;
if (arr[ind][2] <= lo && hi <= arr[ind][3])
join(U[arr[ind][1]], V[arr[ind][1]]);
else
nx.pb({arr[ind][1], arr[ind][2], arr[ind][3]});
}
cnt++;
vi tmp;
for (auto it: nx) {
if (it[1] <= i && i <= it[2]) {
adj[qryD(U[it[0]])].pb(qryD(V[it[0]]));
adj[qryD(V[it[0]])].pb(qryD(U[it[0]]));
tmp.pb(qryD(U[it[0]]));
tmp.pb(qryD(V[it[0]]));
}
}
ans[i] = 0;
dfs(qryD(s), ans[i]);
for (int j: tmp)
adj[j].clear();
}
}
int main() {
mem(ans,-1);
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) scanf("%d %d %d", &U[i], &V[i], &W[i]);
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int t, b, r; scanf("%d %d %d", &t, &b, &r);
if (t == 1) {
b--;
arr.pb({W[b], b, st[b], i});
W[b] = r, st[b] = i+1;
} else {
qry.pb({r, i, b});
}
}
for (int i = 0; i < m; i++)
arr.pb({W[i], i, st[i], q-1});
sort(arr.rbegin(), arr.rend());
reverse(qry.begin(), qry.end());
for (int i = 0; i < q; i += BLOCK) solve(i, min(q,i+BLOCK)-1);
for (int i = 0; i < q; i++)
if (~ans[i])
printf("%d\n", ans[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bridges.cpp: In function 'void solve(int, int)':
bridges.cpp:76:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; ind < arr.size() && w <= arr[ind][0]; ind++) {
~~~~^~~~~~~~~~~~
bridges.cpp: In function 'int main()':
bridges.cpp:102:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
bridges.cpp:103:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i = 0; i < m; i++) scanf("%d %d %d", &U[i], &V[i], &W[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:104:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
~~~~~^~~~~~~~~~
bridges.cpp:106:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int t, b, r; scanf("%d %d %d", &t, &b, &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |