답안 #253738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253738 2020-07-28T15:22:19 Z Saboon 다리 (APIO19_bridges) C++14
73 / 100
3000 ms 11500 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 20;
const int SQ = 333;

int E1[maxn], E2[maxn], W[maxn], Wtmp[maxn], Q1[maxn], Q2[maxn], Qtype[maxn];
bool modify[maxn], visited[maxn];
vector<int> g[maxn];
int par[maxn], ans[maxn];

void dfsoff(int v){
	visited[v] = 0;
	for (auto u : g[v])
		if (visited[u])
			dfsoff(u);
}

int dfs(int v){
	int ret = -par[v];
	visited[v] = 1;
	for (auto u : g[v])
		if (!visited[u])
			ret += dfs(u);
	return ret;
}

int get_par(int v){ return par[v] < 0 ? v : par[v] = get_par(par[v]); }
void merge(int v, int u){
	if ((v = get_par(v)) == (u = get_par(u)))
		return;
	if (par[v] > par[u])
		swap(v, u);
	par[v] += par[u];
	par[u] = v;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> Edge;
	for (int i = 1; i <= m; i++){
		cin >> E1[i] >> E2[i] >> W[i];
		Edge.push_back(i);
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
		cin >> Qtype[i] >> Q1[i] >> Q2[i];
	for (int i = 0; i < q; i += SQ){
		memset(par, -1, sizeof par);
		int l = i, r = min(i+SQ,q);
		vector<int> a, b;
		for (int j = l; j < r; j++){
			if (Qtype[j] == 1)
				modify[Q1[j]] = 1, b.push_back(Q1[j]);
			if (Qtype[j] == 2)
				a.push_back(j);
		}
		sort(b.begin(), b.end());
		b.resize(unique(b.begin(),b.end())-b.begin());
		sort(a.begin(), a.end(), [](int x, int y){return Q2[x] > Q2[y];});
		sort(Edge.begin(), Edge.end(), [](int x, int y){return W[x] > W[y];});
		int ptr = 0;
		for (int x = l; x < r; x++)
			if (Qtype[x] == 1)
				Wtmp[Q1[x]] = W[Q1[x]];
		for (auto j : a){
			while (ptr < m and W[Edge[ptr]] >= Q2[j]){
				if (!modify[Edge[ptr]])
					merge(E1[Edge[ptr]], E2[Edge[ptr]]);
				ptr ++;
			}
			for (int x = l; x < j; x++)
				if (Qtype[x] == 1)
					W[Q1[x]] = Q2[x];
			for (auto x : b){
				if (W[x] >= Q2[j]){ 
					g[get_par(E1[x])].push_back(get_par(E2[x]));
					g[get_par(E2[x])].push_back(get_par(E1[x]));
				}
			}
			ans[j] = dfs(get_par(Q1[j]));
			dfsoff(get_par(Q1[j]));
			for (auto x : b)
				if (W[x] >= Q2[j])
					g[get_par(E1[x])].pop_back(), g[get_par(E2[x])].pop_back();
			for (int x = l; x < j; x++)
				if (Qtype[x] == 1)
					W[Q1[x]] = Wtmp[Q1[x]];
		}
		for (int j = l; j < r; j++)
			if (Qtype[j] == 1)
				modify[Q1[j]] = 0, W[Q1[j]] = Q2[j];
	}
	for (int i = 0; i < q; i++)
		if (Qtype[i] == 2)
			cout << ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3072 KB Output is correct
2 Correct 2 ms 3072 KB Output is correct
3 Correct 34 ms 3576 KB Output is correct
4 Correct 11 ms 3456 KB Output is correct
5 Correct 24 ms 3456 KB Output is correct
6 Correct 22 ms 3456 KB Output is correct
7 Correct 25 ms 3456 KB Output is correct
8 Correct 24 ms 3456 KB Output is correct
9 Correct 29 ms 3448 KB Output is correct
10 Correct 21 ms 3456 KB Output is correct
11 Correct 20 ms 3456 KB Output is correct
12 Correct 23 ms 3576 KB Output is correct
13 Correct 28 ms 3456 KB Output is correct
14 Correct 26 ms 3456 KB Output is correct
15 Correct 25 ms 3456 KB Output is correct
16 Correct 25 ms 3448 KB Output is correct
17 Correct 25 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1908 ms 9852 KB Output is correct
2 Correct 1847 ms 9868 KB Output is correct
3 Correct 1898 ms 9984 KB Output is correct
4 Correct 1833 ms 9976 KB Output is correct
5 Correct 1828 ms 9976 KB Output is correct
6 Correct 2207 ms 9004 KB Output is correct
7 Correct 2140 ms 8800 KB Output is correct
8 Correct 2185 ms 9168 KB Output is correct
9 Correct 79 ms 6240 KB Output is correct
10 Correct 1371 ms 8952 KB Output is correct
11 Correct 1248 ms 8824 KB Output is correct
12 Correct 1615 ms 9164 KB Output is correct
13 Correct 1704 ms 9120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1298 ms 8856 KB Output is correct
2 Correct 650 ms 6904 KB Output is correct
3 Correct 1399 ms 8568 KB Output is correct
4 Correct 1276 ms 8824 KB Output is correct
5 Correct 75 ms 6264 KB Output is correct
6 Correct 1330 ms 8856 KB Output is correct
7 Correct 1233 ms 8704 KB Output is correct
8 Correct 1161 ms 8668 KB Output is correct
9 Correct 1077 ms 8456 KB Output is correct
10 Correct 995 ms 8320 KB Output is correct
11 Correct 1004 ms 8896 KB Output is correct
12 Correct 944 ms 8732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2017 ms 10952 KB Output is correct
2 Correct 78 ms 6264 KB Output is correct
3 Correct 198 ms 6896 KB Output is correct
4 Correct 132 ms 6900 KB Output is correct
5 Correct 1477 ms 9712 KB Output is correct
6 Correct 2003 ms 10688 KB Output is correct
7 Correct 1425 ms 9260 KB Output is correct
8 Correct 1016 ms 8568 KB Output is correct
9 Correct 1028 ms 8700 KB Output is correct
10 Correct 1040 ms 8568 KB Output is correct
11 Correct 1758 ms 9620 KB Output is correct
12 Correct 1670 ms 9588 KB Output is correct
13 Correct 1717 ms 9588 KB Output is correct
14 Correct 1308 ms 9328 KB Output is correct
15 Correct 1358 ms 9460 KB Output is correct
16 Correct 2258 ms 10616 KB Output is correct
17 Correct 2184 ms 10512 KB Output is correct
18 Correct 2208 ms 10604 KB Output is correct
19 Correct 2218 ms 10852 KB Output is correct
20 Correct 2048 ms 10164 KB Output is correct
21 Correct 1999 ms 9972 KB Output is correct
22 Correct 2153 ms 10600 KB Output is correct
23 Correct 1614 ms 8800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1908 ms 9852 KB Output is correct
2 Correct 1847 ms 9868 KB Output is correct
3 Correct 1898 ms 9984 KB Output is correct
4 Correct 1833 ms 9976 KB Output is correct
5 Correct 1828 ms 9976 KB Output is correct
6 Correct 2207 ms 9004 KB Output is correct
7 Correct 2140 ms 8800 KB Output is correct
8 Correct 2185 ms 9168 KB Output is correct
9 Correct 79 ms 6240 KB Output is correct
10 Correct 1371 ms 8952 KB Output is correct
11 Correct 1248 ms 8824 KB Output is correct
12 Correct 1615 ms 9164 KB Output is correct
13 Correct 1704 ms 9120 KB Output is correct
14 Correct 1298 ms 8856 KB Output is correct
15 Correct 650 ms 6904 KB Output is correct
16 Correct 1399 ms 8568 KB Output is correct
17 Correct 1276 ms 8824 KB Output is correct
18 Correct 75 ms 6264 KB Output is correct
19 Correct 1330 ms 8856 KB Output is correct
20 Correct 1233 ms 8704 KB Output is correct
21 Correct 1161 ms 8668 KB Output is correct
22 Correct 1077 ms 8456 KB Output is correct
23 Correct 995 ms 8320 KB Output is correct
24 Correct 1004 ms 8896 KB Output is correct
25 Correct 944 ms 8732 KB Output is correct
26 Correct 1950 ms 9964 KB Output is correct
27 Correct 2217 ms 9744 KB Output is correct
28 Correct 2064 ms 9884 KB Output is correct
29 Correct 1788 ms 9796 KB Output is correct
30 Correct 2288 ms 9808 KB Output is correct
31 Correct 2168 ms 9820 KB Output is correct
32 Correct 2182 ms 9848 KB Output is correct
33 Correct 2003 ms 9976 KB Output is correct
34 Correct 2001 ms 10088 KB Output is correct
35 Correct 2017 ms 10068 KB Output is correct
36 Correct 1793 ms 9968 KB Output is correct
37 Correct 1735 ms 9852 KB Output is correct
38 Correct 1782 ms 9900 KB Output is correct
39 Correct 1656 ms 9476 KB Output is correct
40 Correct 1648 ms 9276 KB Output is correct
41 Correct 1632 ms 9412 KB Output is correct
42 Correct 1670 ms 9920 KB Output is correct
43 Correct 1522 ms 9896 KB Output is correct
44 Correct 1506 ms 10016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3072 KB Output is correct
2 Correct 2 ms 3072 KB Output is correct
3 Correct 34 ms 3576 KB Output is correct
4 Correct 11 ms 3456 KB Output is correct
5 Correct 24 ms 3456 KB Output is correct
6 Correct 22 ms 3456 KB Output is correct
7 Correct 25 ms 3456 KB Output is correct
8 Correct 24 ms 3456 KB Output is correct
9 Correct 29 ms 3448 KB Output is correct
10 Correct 21 ms 3456 KB Output is correct
11 Correct 20 ms 3456 KB Output is correct
12 Correct 23 ms 3576 KB Output is correct
13 Correct 28 ms 3456 KB Output is correct
14 Correct 26 ms 3456 KB Output is correct
15 Correct 25 ms 3456 KB Output is correct
16 Correct 25 ms 3448 KB Output is correct
17 Correct 25 ms 3448 KB Output is correct
18 Correct 1908 ms 9852 KB Output is correct
19 Correct 1847 ms 9868 KB Output is correct
20 Correct 1898 ms 9984 KB Output is correct
21 Correct 1833 ms 9976 KB Output is correct
22 Correct 1828 ms 9976 KB Output is correct
23 Correct 2207 ms 9004 KB Output is correct
24 Correct 2140 ms 8800 KB Output is correct
25 Correct 2185 ms 9168 KB Output is correct
26 Correct 79 ms 6240 KB Output is correct
27 Correct 1371 ms 8952 KB Output is correct
28 Correct 1248 ms 8824 KB Output is correct
29 Correct 1615 ms 9164 KB Output is correct
30 Correct 1704 ms 9120 KB Output is correct
31 Correct 1298 ms 8856 KB Output is correct
32 Correct 650 ms 6904 KB Output is correct
33 Correct 1399 ms 8568 KB Output is correct
34 Correct 1276 ms 8824 KB Output is correct
35 Correct 75 ms 6264 KB Output is correct
36 Correct 1330 ms 8856 KB Output is correct
37 Correct 1233 ms 8704 KB Output is correct
38 Correct 1161 ms 8668 KB Output is correct
39 Correct 1077 ms 8456 KB Output is correct
40 Correct 995 ms 8320 KB Output is correct
41 Correct 1004 ms 8896 KB Output is correct
42 Correct 944 ms 8732 KB Output is correct
43 Correct 2017 ms 10952 KB Output is correct
44 Correct 78 ms 6264 KB Output is correct
45 Correct 198 ms 6896 KB Output is correct
46 Correct 132 ms 6900 KB Output is correct
47 Correct 1477 ms 9712 KB Output is correct
48 Correct 2003 ms 10688 KB Output is correct
49 Correct 1425 ms 9260 KB Output is correct
50 Correct 1016 ms 8568 KB Output is correct
51 Correct 1028 ms 8700 KB Output is correct
52 Correct 1040 ms 8568 KB Output is correct
53 Correct 1758 ms 9620 KB Output is correct
54 Correct 1670 ms 9588 KB Output is correct
55 Correct 1717 ms 9588 KB Output is correct
56 Correct 1308 ms 9328 KB Output is correct
57 Correct 1358 ms 9460 KB Output is correct
58 Correct 2258 ms 10616 KB Output is correct
59 Correct 2184 ms 10512 KB Output is correct
60 Correct 2208 ms 10604 KB Output is correct
61 Correct 2218 ms 10852 KB Output is correct
62 Correct 2048 ms 10164 KB Output is correct
63 Correct 1999 ms 9972 KB Output is correct
64 Correct 2153 ms 10600 KB Output is correct
65 Correct 1614 ms 8800 KB Output is correct
66 Correct 1950 ms 9964 KB Output is correct
67 Correct 2217 ms 9744 KB Output is correct
68 Correct 2064 ms 9884 KB Output is correct
69 Correct 1788 ms 9796 KB Output is correct
70 Correct 2288 ms 9808 KB Output is correct
71 Correct 2168 ms 9820 KB Output is correct
72 Correct 2182 ms 9848 KB Output is correct
73 Correct 2003 ms 9976 KB Output is correct
74 Correct 2001 ms 10088 KB Output is correct
75 Correct 2017 ms 10068 KB Output is correct
76 Correct 1793 ms 9968 KB Output is correct
77 Correct 1735 ms 9852 KB Output is correct
78 Correct 1782 ms 9900 KB Output is correct
79 Correct 1656 ms 9476 KB Output is correct
80 Correct 1648 ms 9276 KB Output is correct
81 Correct 1632 ms 9412 KB Output is correct
82 Correct 1670 ms 9920 KB Output is correct
83 Correct 1522 ms 9896 KB Output is correct
84 Correct 1506 ms 10016 KB Output is correct
85 Execution timed out 3088 ms 11500 KB Time limit exceeded
86 Halted 0 ms 0 KB -