# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
121416 |
2019-06-26T13:45:26 Z |
abacaba |
Bridges (APIO19_bridges) |
C++14 |
|
3000 ms |
17596 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define e first
#define w second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
struct edge {
int u, v, w, ind;
bool operator < (const edge &b) const {
if(w == b.w)
return ind > b.ind;
return w > b.w;
}
};
struct query {
int v, w, updatesTillNow, ind;
bool operator < (const query &b) const {
return w > b.w;
}
};
const int block = 500;
const int N = 1e5 + 1;
int n, m, q, ans[N], p[N], sz[N], szupd, szqq;
vector <int> g[N];
set <edge> edges;
vector <int> was;
edge last[N], back[N];
query qq[N];
pii upd[N];
edge e[N];
bool used[N], usedupd[N];
int find(int v) {
if(v == p[v])
return v;
return p[v] = find(p[v]);
}
inline void unio(int a, int b) {
a = find(a);
b = find(b);
if(a != b) {
if(sz[a] < sz[b])
swap(a, b);
p[b] = a;
sz[a] += sz[b];
}
}
void dfs(int v, int ind, int w) {
used[v] = true;
was.pb(v);
ans[ind] += sz[v];
for(int to : g[v])
if(!used[to])
dfs(to, ind, w);
}
inline void solve() {
sort(qq, qq + szqq);
for(int i = 0; i < szupd; ++i)
edges.erase(e[upd[i].e]);
set <edge>::iterator it = edges.end();
if(!edges.empty())
it = edges.begin();
for(int i = 1; i <= n; ++i)
p[i] = i, sz[i] = 1;
for(int k = 0; k < szqq; ++k) {
query cur = qq[k];
while(it != edges.end() && it->w >= cur.w) {
unio(it->v, it->u);
++it;
}
for(int i = cur.updatesTillNow - 1; i >= 0; --i) {
if(!usedupd[upd[i].e]) {
edge x = e[upd[i].e];
x.w = upd[i].w;
int a = find(x.u), b = find(x.v);
if(x.w >= cur.w && a != b) {
g[a].pb(b);
g[b].pb(a);
}
}
usedupd[upd[i].e] = true;
}
for(int i = cur.updatesTillNow; i < szupd; ++i) {
if(!usedupd[upd[i].e]) {
edge x = back[i];
int a = find(x.u), b = find(x.v);
if(x.w >= cur.w && a != b) {
g[a].pb(b);
g[b].pb(a);
}
}
usedupd[upd[i].e] = true;
}
dfs(find(cur.v), cur.ind, cur.w);
for(int i = 0; i < szupd; ++i) {
usedupd[upd[i].e] = false;
g[find(e[upd[i].e].u)].clear();
g[find(e[upd[i].e].v)].clear();
}
while(!was.empty()) {
used[was.back()] = false;
was.ppb();
}
}
for(int i = 0; i < szupd; ++i) {
edges.erase(e[upd[i].e]);
e[upd[i].e].w = upd[i].w;
edges.insert(e[upd[i].e]);
}
szqq = szupd = 0;
}
bool start[N];
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++i) {
scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
last[i] = e[i];
e[i].ind = i;
edges.insert(e[i]);
}
scanf("%d", &q);
for(int i = block - 1; i <= q; i += block)
start[i] = true;
for(int i = 1; i <= q; ++i) {
int c;
scanf("%d", &c);
if(c == 1) {
scanf("%d%d", &upd[szupd].e, &upd[szupd].w);
back[szupd] = last[upd[szupd].e];
last[upd[szupd].e] = e[upd[szupd].e];
last[upd[szupd].e].w = upd[szupd].w;
++szupd;
}
else {
scanf("%d%d", &qq[szqq].v, &qq[szqq].w);
qq[szqq].updatesTillNow = szupd;
qq[szqq].ind = i;
++szqq;
}
if(start[i])
solve();
}
solve();
for(int i = 1; i <= q; ++i)
if(ans[i])
printf("%d\n", ans[i]);
return 0;
}
Compilation message
bridges.cpp: In function 'int main()':
bridges.cpp:142: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:144:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:149:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
~~~~~^~~~~~~~~~
bridges.cpp:154:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &c);
~~~~~^~~~~~~~~~
bridges.cpp:156:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &upd[szupd].e, &upd[szupd].w);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:163:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &qq[szqq].v, &qq[szqq].w);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
25 ms |
2936 KB |
Output is correct |
4 |
Correct |
12 ms |
2816 KB |
Output is correct |
5 |
Correct |
24 ms |
2816 KB |
Output is correct |
6 |
Correct |
19 ms |
2816 KB |
Output is correct |
7 |
Correct |
25 ms |
2816 KB |
Output is correct |
8 |
Correct |
21 ms |
2816 KB |
Output is correct |
9 |
Correct |
24 ms |
2816 KB |
Output is correct |
10 |
Correct |
19 ms |
2824 KB |
Output is correct |
11 |
Correct |
19 ms |
2816 KB |
Output is correct |
12 |
Correct |
23 ms |
2816 KB |
Output is correct |
13 |
Correct |
26 ms |
2816 KB |
Output is correct |
14 |
Correct |
22 ms |
2816 KB |
Output is correct |
15 |
Correct |
23 ms |
2816 KB |
Output is correct |
16 |
Correct |
21 ms |
2816 KB |
Output is correct |
17 |
Correct |
20 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1581 ms |
9932 KB |
Output is correct |
2 |
Correct |
1674 ms |
10156 KB |
Output is correct |
3 |
Correct |
1763 ms |
10104 KB |
Output is correct |
4 |
Correct |
1738 ms |
9820 KB |
Output is correct |
5 |
Correct |
1587 ms |
9852 KB |
Output is correct |
6 |
Correct |
1834 ms |
8980 KB |
Output is correct |
7 |
Correct |
1885 ms |
8924 KB |
Output is correct |
8 |
Correct |
1772 ms |
8988 KB |
Output is correct |
9 |
Correct |
44 ms |
3448 KB |
Output is correct |
10 |
Correct |
1165 ms |
9716 KB |
Output is correct |
11 |
Correct |
1393 ms |
9788 KB |
Output is correct |
12 |
Correct |
1095 ms |
8924 KB |
Output is correct |
13 |
Correct |
1335 ms |
8988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
993 ms |
7768 KB |
Output is correct |
2 |
Correct |
581 ms |
4628 KB |
Output is correct |
3 |
Correct |
1210 ms |
7780 KB |
Output is correct |
4 |
Correct |
1068 ms |
7744 KB |
Output is correct |
5 |
Correct |
43 ms |
3320 KB |
Output is correct |
6 |
Correct |
871 ms |
7600 KB |
Output is correct |
7 |
Correct |
880 ms |
7672 KB |
Output is correct |
8 |
Correct |
903 ms |
7728 KB |
Output is correct |
9 |
Correct |
540 ms |
7352 KB |
Output is correct |
10 |
Correct |
566 ms |
7300 KB |
Output is correct |
11 |
Correct |
871 ms |
7644 KB |
Output is correct |
12 |
Correct |
799 ms |
7688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2515 ms |
13756 KB |
Output is correct |
2 |
Correct |
44 ms |
4600 KB |
Output is correct |
3 |
Correct |
347 ms |
14012 KB |
Output is correct |
4 |
Correct |
119 ms |
14104 KB |
Output is correct |
5 |
Correct |
1714 ms |
16100 KB |
Output is correct |
6 |
Correct |
2981 ms |
17476 KB |
Output is correct |
7 |
Correct |
2108 ms |
16000 KB |
Output is correct |
8 |
Correct |
1004 ms |
11240 KB |
Output is correct |
9 |
Correct |
975 ms |
11384 KB |
Output is correct |
10 |
Correct |
1076 ms |
11384 KB |
Output is correct |
11 |
Correct |
2070 ms |
14328 KB |
Output is correct |
12 |
Correct |
2090 ms |
14468 KB |
Output is correct |
13 |
Correct |
2243 ms |
14368 KB |
Output is correct |
14 |
Correct |
1492 ms |
15788 KB |
Output is correct |
15 |
Correct |
1317 ms |
16052 KB |
Output is correct |
16 |
Correct |
2633 ms |
17276 KB |
Output is correct |
17 |
Correct |
2712 ms |
17256 KB |
Output is correct |
18 |
Correct |
2722 ms |
17336 KB |
Output is correct |
19 |
Correct |
2944 ms |
17476 KB |
Output is correct |
20 |
Correct |
1838 ms |
15352 KB |
Output is correct |
21 |
Correct |
2297 ms |
15392 KB |
Output is correct |
22 |
Correct |
2810 ms |
16816 KB |
Output is correct |
23 |
Correct |
1558 ms |
13812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1581 ms |
9932 KB |
Output is correct |
2 |
Correct |
1674 ms |
10156 KB |
Output is correct |
3 |
Correct |
1763 ms |
10104 KB |
Output is correct |
4 |
Correct |
1738 ms |
9820 KB |
Output is correct |
5 |
Correct |
1587 ms |
9852 KB |
Output is correct |
6 |
Correct |
1834 ms |
8980 KB |
Output is correct |
7 |
Correct |
1885 ms |
8924 KB |
Output is correct |
8 |
Correct |
1772 ms |
8988 KB |
Output is correct |
9 |
Correct |
44 ms |
3448 KB |
Output is correct |
10 |
Correct |
1165 ms |
9716 KB |
Output is correct |
11 |
Correct |
1393 ms |
9788 KB |
Output is correct |
12 |
Correct |
1095 ms |
8924 KB |
Output is correct |
13 |
Correct |
1335 ms |
8988 KB |
Output is correct |
14 |
Correct |
993 ms |
7768 KB |
Output is correct |
15 |
Correct |
581 ms |
4628 KB |
Output is correct |
16 |
Correct |
1210 ms |
7780 KB |
Output is correct |
17 |
Correct |
1068 ms |
7744 KB |
Output is correct |
18 |
Correct |
43 ms |
3320 KB |
Output is correct |
19 |
Correct |
871 ms |
7600 KB |
Output is correct |
20 |
Correct |
880 ms |
7672 KB |
Output is correct |
21 |
Correct |
903 ms |
7728 KB |
Output is correct |
22 |
Correct |
540 ms |
7352 KB |
Output is correct |
23 |
Correct |
566 ms |
7300 KB |
Output is correct |
24 |
Correct |
871 ms |
7644 KB |
Output is correct |
25 |
Correct |
799 ms |
7688 KB |
Output is correct |
26 |
Correct |
1522 ms |
10088 KB |
Output is correct |
27 |
Correct |
1698 ms |
9952 KB |
Output is correct |
28 |
Correct |
1799 ms |
10004 KB |
Output is correct |
29 |
Correct |
1709 ms |
9784 KB |
Output is correct |
30 |
Correct |
2203 ms |
10012 KB |
Output is correct |
31 |
Correct |
2457 ms |
9940 KB |
Output is correct |
32 |
Correct |
2105 ms |
9952 KB |
Output is correct |
33 |
Correct |
2095 ms |
9780 KB |
Output is correct |
34 |
Correct |
1909 ms |
9848 KB |
Output is correct |
35 |
Correct |
2072 ms |
10044 KB |
Output is correct |
36 |
Correct |
1598 ms |
9852 KB |
Output is correct |
37 |
Correct |
1403 ms |
9760 KB |
Output is correct |
38 |
Correct |
1339 ms |
9892 KB |
Output is correct |
39 |
Correct |
846 ms |
9200 KB |
Output is correct |
40 |
Correct |
812 ms |
9308 KB |
Output is correct |
41 |
Correct |
874 ms |
9208 KB |
Output is correct |
42 |
Correct |
1078 ms |
9980 KB |
Output is correct |
43 |
Correct |
1053 ms |
10028 KB |
Output is correct |
44 |
Correct |
999 ms |
9976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
25 ms |
2936 KB |
Output is correct |
4 |
Correct |
12 ms |
2816 KB |
Output is correct |
5 |
Correct |
24 ms |
2816 KB |
Output is correct |
6 |
Correct |
19 ms |
2816 KB |
Output is correct |
7 |
Correct |
25 ms |
2816 KB |
Output is correct |
8 |
Correct |
21 ms |
2816 KB |
Output is correct |
9 |
Correct |
24 ms |
2816 KB |
Output is correct |
10 |
Correct |
19 ms |
2824 KB |
Output is correct |
11 |
Correct |
19 ms |
2816 KB |
Output is correct |
12 |
Correct |
23 ms |
2816 KB |
Output is correct |
13 |
Correct |
26 ms |
2816 KB |
Output is correct |
14 |
Correct |
22 ms |
2816 KB |
Output is correct |
15 |
Correct |
23 ms |
2816 KB |
Output is correct |
16 |
Correct |
21 ms |
2816 KB |
Output is correct |
17 |
Correct |
20 ms |
2816 KB |
Output is correct |
18 |
Correct |
1581 ms |
9932 KB |
Output is correct |
19 |
Correct |
1674 ms |
10156 KB |
Output is correct |
20 |
Correct |
1763 ms |
10104 KB |
Output is correct |
21 |
Correct |
1738 ms |
9820 KB |
Output is correct |
22 |
Correct |
1587 ms |
9852 KB |
Output is correct |
23 |
Correct |
1834 ms |
8980 KB |
Output is correct |
24 |
Correct |
1885 ms |
8924 KB |
Output is correct |
25 |
Correct |
1772 ms |
8988 KB |
Output is correct |
26 |
Correct |
44 ms |
3448 KB |
Output is correct |
27 |
Correct |
1165 ms |
9716 KB |
Output is correct |
28 |
Correct |
1393 ms |
9788 KB |
Output is correct |
29 |
Correct |
1095 ms |
8924 KB |
Output is correct |
30 |
Correct |
1335 ms |
8988 KB |
Output is correct |
31 |
Correct |
993 ms |
7768 KB |
Output is correct |
32 |
Correct |
581 ms |
4628 KB |
Output is correct |
33 |
Correct |
1210 ms |
7780 KB |
Output is correct |
34 |
Correct |
1068 ms |
7744 KB |
Output is correct |
35 |
Correct |
43 ms |
3320 KB |
Output is correct |
36 |
Correct |
871 ms |
7600 KB |
Output is correct |
37 |
Correct |
880 ms |
7672 KB |
Output is correct |
38 |
Correct |
903 ms |
7728 KB |
Output is correct |
39 |
Correct |
540 ms |
7352 KB |
Output is correct |
40 |
Correct |
566 ms |
7300 KB |
Output is correct |
41 |
Correct |
871 ms |
7644 KB |
Output is correct |
42 |
Correct |
799 ms |
7688 KB |
Output is correct |
43 |
Correct |
2515 ms |
13756 KB |
Output is correct |
44 |
Correct |
44 ms |
4600 KB |
Output is correct |
45 |
Correct |
347 ms |
14012 KB |
Output is correct |
46 |
Correct |
119 ms |
14104 KB |
Output is correct |
47 |
Correct |
1714 ms |
16100 KB |
Output is correct |
48 |
Correct |
2981 ms |
17476 KB |
Output is correct |
49 |
Correct |
2108 ms |
16000 KB |
Output is correct |
50 |
Correct |
1004 ms |
11240 KB |
Output is correct |
51 |
Correct |
975 ms |
11384 KB |
Output is correct |
52 |
Correct |
1076 ms |
11384 KB |
Output is correct |
53 |
Correct |
2070 ms |
14328 KB |
Output is correct |
54 |
Correct |
2090 ms |
14468 KB |
Output is correct |
55 |
Correct |
2243 ms |
14368 KB |
Output is correct |
56 |
Correct |
1492 ms |
15788 KB |
Output is correct |
57 |
Correct |
1317 ms |
16052 KB |
Output is correct |
58 |
Correct |
2633 ms |
17276 KB |
Output is correct |
59 |
Correct |
2712 ms |
17256 KB |
Output is correct |
60 |
Correct |
2722 ms |
17336 KB |
Output is correct |
61 |
Correct |
2944 ms |
17476 KB |
Output is correct |
62 |
Correct |
1838 ms |
15352 KB |
Output is correct |
63 |
Correct |
2297 ms |
15392 KB |
Output is correct |
64 |
Correct |
2810 ms |
16816 KB |
Output is correct |
65 |
Correct |
1558 ms |
13812 KB |
Output is correct |
66 |
Correct |
1522 ms |
10088 KB |
Output is correct |
67 |
Correct |
1698 ms |
9952 KB |
Output is correct |
68 |
Correct |
1799 ms |
10004 KB |
Output is correct |
69 |
Correct |
1709 ms |
9784 KB |
Output is correct |
70 |
Correct |
2203 ms |
10012 KB |
Output is correct |
71 |
Correct |
2457 ms |
9940 KB |
Output is correct |
72 |
Correct |
2105 ms |
9952 KB |
Output is correct |
73 |
Correct |
2095 ms |
9780 KB |
Output is correct |
74 |
Correct |
1909 ms |
9848 KB |
Output is correct |
75 |
Correct |
2072 ms |
10044 KB |
Output is correct |
76 |
Correct |
1598 ms |
9852 KB |
Output is correct |
77 |
Correct |
1403 ms |
9760 KB |
Output is correct |
78 |
Correct |
1339 ms |
9892 KB |
Output is correct |
79 |
Correct |
846 ms |
9200 KB |
Output is correct |
80 |
Correct |
812 ms |
9308 KB |
Output is correct |
81 |
Correct |
874 ms |
9208 KB |
Output is correct |
82 |
Correct |
1078 ms |
9980 KB |
Output is correct |
83 |
Correct |
1053 ms |
10028 KB |
Output is correct |
84 |
Correct |
999 ms |
9976 KB |
Output is correct |
85 |
Execution timed out |
3030 ms |
17596 KB |
Time limit exceeded |
86 |
Halted |
0 ms |
0 KB |
- |