답안 #601301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
601301 2022-07-21T16:00:31 Z patrikpavic2 Stranded Far From Home (BOI22_island) C++17
100 / 100
305 ms 43284 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef vector < int > vi;
typedef long long ll;

const int N = 2e5 + 500;

vector < int > v[N], rd, T[N];
int n, m, vel[N], bio[N], jed[N];
int par[N], naj[N], dobar[N], ppar[N];
ll sm[N];

int pr_jed(int x){
	if(jed[x] == x) return x;
	return jed[x] = pr_jed(jed[x]);
}

int pr(int x){
	if(x == ppar[x]) return x;
	return ppar[x] = pr(ppar[x]);
}

bool cmp_vel(int A, int B){
	return vel[A] < vel[B];
}

void dfs(int x){
	for(int y : T[x]){
		dfs(y); 
		sm[x] += sm[y];
	}
	sm[x] += vel[x];
}


int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1;i <= n;i++){
		scanf("%d", vel + i), rd.PB(i);
		jed[i] = i; ppar[i] = i;
	}
	for(int i = 0;i < m;i++){
		int a, b; scanf("%d%d", &a, &b);
		v[a].PB(b), v[b].PB(a);	
	}
	sort(rd.begin(), rd.end(), cmp_vel);
	for(int x : rd){
		bio[x] = 1;
		for(int y : v[x]){
			if(!bio[y]) continue;
			T[x].PB(pr(y));
		}
		sort(T[x].begin(), T[x].end());
		T[x].erase(unique(T[x].begin(), T[x].end()), T[x].end());
		for(int y : T[x]){
			if(vel[y] == vel[x]) 
				jed[pr_jed(y)] = pr_jed(x);
			par[y] = x; ppar[y] = x;
		}
	}
	reverse(rd.begin(), rd.end());
	dfs(rd[0]);
	for(int x : rd){
		if(!par[x] || (dobar[pr_jed(par[x])] && sm[x] >= vel[par[x]]))
			dobar[x] = 1;
	}
	for(int i = 1;i <= n;i++)
		printf("%d", dobar[pr_jed(i)]);
	printf("\n");
	return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
island.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d", vel + i), rd.PB(i);
      |   ~~~~~^~~~~~~~~~~~~~~
island.cpp:52:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   int a, b; scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9908 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9856 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 8 ms 9900 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 8 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 6 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9748 KB Output is correct
3 Correct 182 ms 31308 KB Output is correct
4 Correct 165 ms 28004 KB Output is correct
5 Correct 185 ms 26592 KB Output is correct
6 Correct 260 ms 27120 KB Output is correct
7 Correct 183 ms 27108 KB Output is correct
8 Correct 219 ms 28432 KB Output is correct
9 Correct 157 ms 25848 KB Output is correct
10 Correct 126 ms 24088 KB Output is correct
11 Correct 132 ms 24880 KB Output is correct
12 Correct 215 ms 26384 KB Output is correct
13 Correct 159 ms 28328 KB Output is correct
14 Correct 161 ms 28276 KB Output is correct
15 Correct 171 ms 38792 KB Output is correct
16 Correct 128 ms 38568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 216 ms 27208 KB Output is correct
3 Correct 222 ms 29932 KB Output is correct
4 Correct 167 ms 33216 KB Output is correct
5 Correct 184 ms 30936 KB Output is correct
6 Correct 228 ms 30704 KB Output is correct
7 Correct 209 ms 42136 KB Output is correct
8 Correct 210 ms 42128 KB Output is correct
9 Correct 121 ms 40980 KB Output is correct
10 Correct 172 ms 28140 KB Output is correct
11 Correct 194 ms 29524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 223 ms 27648 KB Output is correct
3 Correct 231 ms 31688 KB Output is correct
4 Correct 305 ms 28736 KB Output is correct
5 Correct 208 ms 31776 KB Output is correct
6 Correct 209 ms 31388 KB Output is correct
7 Correct 162 ms 28740 KB Output is correct
8 Correct 129 ms 36828 KB Output is correct
9 Correct 137 ms 22048 KB Output is correct
10 Correct 224 ms 27836 KB Output is correct
11 Correct 198 ms 28128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9908 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9856 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 8 ms 9900 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 8 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 6 ms 9812 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9748 KB Output is correct
17 Correct 182 ms 31308 KB Output is correct
18 Correct 165 ms 28004 KB Output is correct
19 Correct 185 ms 26592 KB Output is correct
20 Correct 260 ms 27120 KB Output is correct
21 Correct 183 ms 27108 KB Output is correct
22 Correct 219 ms 28432 KB Output is correct
23 Correct 157 ms 25848 KB Output is correct
24 Correct 126 ms 24088 KB Output is correct
25 Correct 132 ms 24880 KB Output is correct
26 Correct 215 ms 26384 KB Output is correct
27 Correct 159 ms 28328 KB Output is correct
28 Correct 161 ms 28276 KB Output is correct
29 Correct 171 ms 38792 KB Output is correct
30 Correct 128 ms 38568 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 216 ms 27208 KB Output is correct
33 Correct 222 ms 29932 KB Output is correct
34 Correct 167 ms 33216 KB Output is correct
35 Correct 184 ms 30936 KB Output is correct
36 Correct 228 ms 30704 KB Output is correct
37 Correct 209 ms 42136 KB Output is correct
38 Correct 210 ms 42128 KB Output is correct
39 Correct 121 ms 40980 KB Output is correct
40 Correct 172 ms 28140 KB Output is correct
41 Correct 194 ms 29524 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 223 ms 27648 KB Output is correct
44 Correct 231 ms 31688 KB Output is correct
45 Correct 305 ms 28736 KB Output is correct
46 Correct 208 ms 31776 KB Output is correct
47 Correct 209 ms 31388 KB Output is correct
48 Correct 162 ms 28740 KB Output is correct
49 Correct 129 ms 36828 KB Output is correct
50 Correct 137 ms 22048 KB Output is correct
51 Correct 224 ms 27836 KB Output is correct
52 Correct 198 ms 28128 KB Output is correct
53 Correct 6 ms 9712 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 8 ms 9688 KB Output is correct
56 Correct 6 ms 9856 KB Output is correct
57 Correct 7 ms 9940 KB Output is correct
58 Correct 7 ms 9892 KB Output is correct
59 Correct 8 ms 9812 KB Output is correct
60 Correct 8 ms 9812 KB Output is correct
61 Correct 6 ms 9984 KB Output is correct
62 Correct 6 ms 9864 KB Output is correct
63 Correct 7 ms 9836 KB Output is correct
64 Correct 6 ms 9812 KB Output is correct
65 Correct 6 ms 9956 KB Output is correct
66 Correct 7 ms 9812 KB Output is correct
67 Correct 182 ms 34208 KB Output is correct
68 Correct 185 ms 30048 KB Output is correct
69 Correct 185 ms 27520 KB Output is correct
70 Correct 209 ms 29272 KB Output is correct
71 Correct 206 ms 28604 KB Output is correct
72 Correct 205 ms 30776 KB Output is correct
73 Correct 195 ms 28380 KB Output is correct
74 Correct 134 ms 25336 KB Output is correct
75 Correct 132 ms 26356 KB Output is correct
76 Correct 240 ms 27808 KB Output is correct
77 Correct 164 ms 29520 KB Output is correct
78 Correct 161 ms 29636 KB Output is correct
79 Correct 205 ms 41268 KB Output is correct
80 Correct 125 ms 42008 KB Output is correct
81 Correct 226 ms 29576 KB Output is correct
82 Correct 261 ms 30348 KB Output is correct
83 Correct 167 ms 29216 KB Output is correct
84 Correct 172 ms 30584 KB Output is correct
85 Correct 246 ms 31832 KB Output is correct
86 Correct 216 ms 43284 KB Output is correct
87 Correct 218 ms 43016 KB Output is correct
88 Correct 180 ms 27340 KB Output is correct
89 Correct 200 ms 26916 KB Output is correct
90 Correct 255 ms 30188 KB Output is correct
91 Correct 238 ms 31720 KB Output is correct
92 Correct 263 ms 31728 KB Output is correct
93 Correct 246 ms 30848 KB Output is correct
94 Correct 215 ms 30968 KB Output is correct
95 Correct 148 ms 30556 KB Output is correct
96 Correct 129 ms 36524 KB Output is correct
97 Correct 147 ms 22476 KB Output is correct
98 Correct 213 ms 29400 KB Output is correct
99 Correct 186 ms 29508 KB Output is correct
100 Correct 66 ms 15112 KB Output is correct
101 Correct 262 ms 31548 KB Output is correct
102 Correct 174 ms 29216 KB Output is correct
103 Correct 226 ms 27244 KB Output is correct
104 Correct 253 ms 28348 KB Output is correct