/**
____ ____ ____ __________________ ____ ____ ____
||I || ||c || ||e || || || ||M || ||a || ||n ||
||__|| ||__|| ||__|| ||________________|| ||__|| ||__|| ||__||
|/__\| |/__\| |/__\| |/________________\| |/__\| |/__\| |/__\|
*/
#include <iostream>
#include <chrono>
#include <set>
#include <algorithm>
#include <vector>
#define maxn 200005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;
using namespace std;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <ll, int> pli;
typedef long double pd;
ll n, m;
ll s[maxn];
set <ll> v[maxn];
pii sorted[maxn];
void read()
{
cin >> n >> m;
for(ll i = 1; i <= n; i++)
cin >> s[i];
for(ll i = 1; i <= n; i++)
sorted[i] = {s[i], i};
ll x, y;
for(ll i = 1; i <= m; i++)
{
cin >> x >> y;
v[x].insert(y);
v[y].insert(x);
}
sort(sorted + 1, sorted + 1 + n);
/**for(ll i = 1; i <= n; i++)
cout << sorted[i].X << " " << sorted[i].Y << endl;*/
}
ll par[maxn], sz[maxn], sum[maxn];
bool lamp[maxn];
set <ll> nodes[maxn];
ll f(ll node)
{
return node == par[node]? node : par[node] = f(par[node]);
}
void unite(ll a, ll b)
{
a = f(a);
b = f(b);
if(a == b)
return;
if(sz[b] > sz[a])
swap(a, b);
for(auto e : nodes[b])
nodes[a].insert(e);
sum[a] += sum[b];
par[b] = a;
sz[a] += sz[b];
}
void solve()
{
for(ll i = 1; i <= n; i++)
{
nodes[i].clear();
par[i] = i;
sz[i] = 1;
lamp[i] = false;
sum[i] = 0;
}
for(ll i = 1; i <= n; i++)
{
ll curr = sorted[i].Y;
//cout << curr << endl;
vector <ll> act;
for(auto e : v[curr])
if(lamp[e] == true)
act.pb(f(e));
lamp[curr] = true;
nodes[curr].insert(curr);
sum[curr] = s[curr];
for(auto e : act)
if(s[curr] > sum[e])
{
nodes[e].clear();
unite(e, curr);
}
for(auto e : act)
unite(e , curr);
}
for(ll i = 1; i <= n; i++)
{
ll a = f(1);
auto p1 = nodes[a].find(i);
if(p1 == nodes[a].end())
cout << '0';
else
cout << '1';
}
}
int main()
{
/**#ifdef ONLINE_JUDGE /// promeni
freopen("taxi.in", "r", stdin);
freopen("taxi.out", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25680 KB |
Output is correct |
2 |
Correct |
5 ms |
25848 KB |
Output is correct |
3 |
Correct |
4 ms |
25680 KB |
Output is correct |
4 |
Correct |
6 ms |
25904 KB |
Output is correct |
5 |
Correct |
6 ms |
25936 KB |
Output is correct |
6 |
Correct |
7 ms |
26108 KB |
Output is correct |
7 |
Correct |
7 ms |
25936 KB |
Output is correct |
8 |
Correct |
6 ms |
25936 KB |
Output is correct |
9 |
Correct |
6 ms |
25908 KB |
Output is correct |
10 |
Correct |
8 ms |
26192 KB |
Output is correct |
11 |
Correct |
8 ms |
26192 KB |
Output is correct |
12 |
Correct |
7 ms |
26192 KB |
Output is correct |
13 |
Correct |
5 ms |
25936 KB |
Output is correct |
14 |
Correct |
7 ms |
25936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25852 KB |
Output is correct |
2 |
Correct |
5 ms |
25848 KB |
Output is correct |
3 |
Correct |
206 ms |
63944 KB |
Output is correct |
4 |
Correct |
242 ms |
67912 KB |
Output is correct |
5 |
Correct |
271 ms |
77644 KB |
Output is correct |
6 |
Correct |
330 ms |
80708 KB |
Output is correct |
7 |
Correct |
314 ms |
79844 KB |
Output is correct |
8 |
Correct |
225 ms |
69196 KB |
Output is correct |
9 |
Correct |
239 ms |
87888 KB |
Output is correct |
10 |
Correct |
265 ms |
62148 KB |
Output is correct |
11 |
Correct |
267 ms |
68352 KB |
Output is correct |
12 |
Correct |
239 ms |
65068 KB |
Output is correct |
13 |
Correct |
187 ms |
67816 KB |
Output is correct |
14 |
Correct |
207 ms |
68004 KB |
Output is correct |
15 |
Correct |
199 ms |
69448 KB |
Output is correct |
16 |
Correct |
146 ms |
68284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
25680 KB |
Output is correct |
2 |
Correct |
385 ms |
83528 KB |
Output is correct |
3 |
Correct |
398 ms |
87960 KB |
Output is correct |
4 |
Correct |
281 ms |
69344 KB |
Output is correct |
5 |
Correct |
208 ms |
67856 KB |
Output is correct |
6 |
Correct |
361 ms |
87512 KB |
Output is correct |
7 |
Correct |
231 ms |
69516 KB |
Output is correct |
8 |
Correct |
234 ms |
69448 KB |
Output is correct |
9 |
Correct |
157 ms |
68168 KB |
Output is correct |
10 |
Correct |
257 ms |
64072 KB |
Output is correct |
11 |
Correct |
258 ms |
68424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25680 KB |
Output is correct |
2 |
Correct |
402 ms |
69016 KB |
Output is correct |
3 |
Correct |
369 ms |
76616 KB |
Output is correct |
4 |
Correct |
416 ms |
84040 KB |
Output is correct |
5 |
Correct |
469 ms |
94820 KB |
Output is correct |
6 |
Correct |
432 ms |
80712 KB |
Output is correct |
7 |
Correct |
290 ms |
69380 KB |
Output is correct |
8 |
Correct |
127 ms |
63496 KB |
Output is correct |
9 |
Correct |
209 ms |
54856 KB |
Output is correct |
10 |
Correct |
382 ms |
98888 KB |
Output is correct |
11 |
Correct |
220 ms |
68224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
25680 KB |
Output is correct |
2 |
Correct |
5 ms |
25848 KB |
Output is correct |
3 |
Correct |
4 ms |
25680 KB |
Output is correct |
4 |
Correct |
6 ms |
25904 KB |
Output is correct |
5 |
Correct |
6 ms |
25936 KB |
Output is correct |
6 |
Correct |
7 ms |
26108 KB |
Output is correct |
7 |
Correct |
7 ms |
25936 KB |
Output is correct |
8 |
Correct |
6 ms |
25936 KB |
Output is correct |
9 |
Correct |
6 ms |
25908 KB |
Output is correct |
10 |
Correct |
8 ms |
26192 KB |
Output is correct |
11 |
Correct |
8 ms |
26192 KB |
Output is correct |
12 |
Correct |
7 ms |
26192 KB |
Output is correct |
13 |
Correct |
5 ms |
25936 KB |
Output is correct |
14 |
Correct |
7 ms |
25936 KB |
Output is correct |
15 |
Correct |
5 ms |
25852 KB |
Output is correct |
16 |
Correct |
5 ms |
25848 KB |
Output is correct |
17 |
Correct |
206 ms |
63944 KB |
Output is correct |
18 |
Correct |
242 ms |
67912 KB |
Output is correct |
19 |
Correct |
271 ms |
77644 KB |
Output is correct |
20 |
Correct |
330 ms |
80708 KB |
Output is correct |
21 |
Correct |
314 ms |
79844 KB |
Output is correct |
22 |
Correct |
225 ms |
69196 KB |
Output is correct |
23 |
Correct |
239 ms |
87888 KB |
Output is correct |
24 |
Correct |
265 ms |
62148 KB |
Output is correct |
25 |
Correct |
267 ms |
68352 KB |
Output is correct |
26 |
Correct |
239 ms |
65068 KB |
Output is correct |
27 |
Correct |
187 ms |
67816 KB |
Output is correct |
28 |
Correct |
207 ms |
68004 KB |
Output is correct |
29 |
Correct |
199 ms |
69448 KB |
Output is correct |
30 |
Correct |
146 ms |
68284 KB |
Output is correct |
31 |
Correct |
6 ms |
25680 KB |
Output is correct |
32 |
Correct |
385 ms |
83528 KB |
Output is correct |
33 |
Correct |
398 ms |
87960 KB |
Output is correct |
34 |
Correct |
281 ms |
69344 KB |
Output is correct |
35 |
Correct |
208 ms |
67856 KB |
Output is correct |
36 |
Correct |
361 ms |
87512 KB |
Output is correct |
37 |
Correct |
231 ms |
69516 KB |
Output is correct |
38 |
Correct |
234 ms |
69448 KB |
Output is correct |
39 |
Correct |
157 ms |
68168 KB |
Output is correct |
40 |
Correct |
257 ms |
64072 KB |
Output is correct |
41 |
Correct |
258 ms |
68424 KB |
Output is correct |
42 |
Correct |
5 ms |
25680 KB |
Output is correct |
43 |
Correct |
402 ms |
69016 KB |
Output is correct |
44 |
Correct |
369 ms |
76616 KB |
Output is correct |
45 |
Correct |
416 ms |
84040 KB |
Output is correct |
46 |
Correct |
469 ms |
94820 KB |
Output is correct |
47 |
Correct |
432 ms |
80712 KB |
Output is correct |
48 |
Correct |
290 ms |
69380 KB |
Output is correct |
49 |
Correct |
127 ms |
63496 KB |
Output is correct |
50 |
Correct |
209 ms |
54856 KB |
Output is correct |
51 |
Correct |
382 ms |
98888 KB |
Output is correct |
52 |
Correct |
220 ms |
68224 KB |
Output is correct |
53 |
Correct |
4 ms |
25680 KB |
Output is correct |
54 |
Correct |
4 ms |
25692 KB |
Output is correct |
55 |
Correct |
4 ms |
25680 KB |
Output is correct |
56 |
Correct |
6 ms |
25936 KB |
Output is correct |
57 |
Correct |
6 ms |
25936 KB |
Output is correct |
58 |
Correct |
7 ms |
25936 KB |
Output is correct |
59 |
Correct |
6 ms |
25936 KB |
Output is correct |
60 |
Correct |
5 ms |
25968 KB |
Output is correct |
61 |
Correct |
5 ms |
26104 KB |
Output is correct |
62 |
Correct |
6 ms |
26228 KB |
Output is correct |
63 |
Correct |
6 ms |
26192 KB |
Output is correct |
64 |
Correct |
5 ms |
26192 KB |
Output is correct |
65 |
Correct |
5 ms |
25936 KB |
Output is correct |
66 |
Correct |
6 ms |
25916 KB |
Output is correct |
67 |
Correct |
198 ms |
68424 KB |
Output is correct |
68 |
Correct |
233 ms |
67912 KB |
Output is correct |
69 |
Correct |
282 ms |
77604 KB |
Output is correct |
70 |
Correct |
311 ms |
80520 KB |
Output is correct |
71 |
Correct |
353 ms |
79832 KB |
Output is correct |
72 |
Correct |
294 ms |
69308 KB |
Output is correct |
73 |
Correct |
302 ms |
87740 KB |
Output is correct |
74 |
Correct |
253 ms |
62148 KB |
Output is correct |
75 |
Correct |
346 ms |
68436 KB |
Output is correct |
76 |
Correct |
271 ms |
65068 KB |
Output is correct |
77 |
Correct |
214 ms |
67912 KB |
Output is correct |
78 |
Correct |
243 ms |
67912 KB |
Output is correct |
79 |
Correct |
242 ms |
69448 KB |
Output is correct |
80 |
Correct |
157 ms |
68168 KB |
Output is correct |
81 |
Correct |
394 ms |
88152 KB |
Output is correct |
82 |
Correct |
400 ms |
88100 KB |
Output is correct |
83 |
Correct |
245 ms |
69448 KB |
Output is correct |
84 |
Correct |
187 ms |
67912 KB |
Output is correct |
85 |
Correct |
338 ms |
87632 KB |
Output is correct |
86 |
Correct |
237 ms |
69464 KB |
Output is correct |
87 |
Correct |
213 ms |
69452 KB |
Output is correct |
88 |
Correct |
215 ms |
64072 KB |
Output is correct |
89 |
Correct |
228 ms |
68424 KB |
Output is correct |
90 |
Correct |
334 ms |
73584 KB |
Output is correct |
91 |
Correct |
326 ms |
76528 KB |
Output is correct |
92 |
Correct |
385 ms |
84040 KB |
Output is correct |
93 |
Correct |
455 ms |
94900 KB |
Output is correct |
94 |
Correct |
400 ms |
80520 KB |
Output is correct |
95 |
Correct |
329 ms |
69384 KB |
Output is correct |
96 |
Correct |
146 ms |
63596 KB |
Output is correct |
97 |
Correct |
237 ms |
54884 KB |
Output is correct |
98 |
Correct |
441 ms |
99144 KB |
Output is correct |
99 |
Correct |
249 ms |
68168 KB |
Output is correct |
100 |
Correct |
199 ms |
46608 KB |
Output is correct |
101 |
Correct |
474 ms |
77896 KB |
Output is correct |
102 |
Correct |
353 ms |
69960 KB |
Output is correct |
103 |
Correct |
330 ms |
64584 KB |
Output is correct |
104 |
Correct |
358 ms |
70472 KB |
Output is correct |