// wygzgyw
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
t=0; char ch=getchar(); int f=1;
while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
template <typename T> void write(T t) {
if (t<0) { putchar('-'); write(-t); return; }
if (t>9) write(t/10);
putchar('0'+t%10);
}
template <typename T> void writeln(T t) { write(t); puts(""); }
#define MP make_pair
typedef long long ll;
const int maxn=(4e5)+10;
int n,m;
ll s[maxn],t[maxn];
vector<int> g[maxn];
struct node {
int x,y;
friend bool operator < (node A,node B) { return s[A.x]<s[B.x]; }
} E[maxn];
int fa[maxn],f[maxn],tot;
int find(int x) {
if (fa[x]==x) return x;
return fa[x]=find(fa[x]);
}
bool mk[maxn];
char S[maxn];
void dfs(int u) {
if (mk[u]) return;
if (u<=n) S[u]='1';
for (int &v : g[u]) dfs(v);
}
int main() {
read(n),read(m);
for (int i=1;i<=n;i++) read(s[i]),t[i]=s[i],f[i]=fa[i]=i;
tot=n;
int x,y;
for (int i=1;i<=m;i++) {
read(x),read(y);
if (s[x]<s[y]) swap(x,y);
E[i]=(node){x,y};
}
sort(E+1,E+m+1);
for (int i=1;i<=m;i++) {
x=E[i].x,y=E[i].y;
if (find(x)==find(y)) continue;
y=find(y);
if (t[y]<s[x]) mk[f[y]]=1;
x=find(x);
fa[x]=y,t[y]+=t[x],tot++;
g[tot].push_back(f[x]),g[tot].push_back(f[y]);
f[x]=tot,f[y]=tot;
}
for (int i=1;i<=n;i++) S[i]='0';
dfs(tot);
printf("%s\n",S+1);
return 0;
}
/*
0. Enough array size? Enough array size? Enough array size? Integer overflow?
1. Think TWICE, Code ONCE!
Are there any counterexamples to your algo?
2. Be careful about the BOUNDARIES!
N=1? P=1? Something about 0?
3. Do not make STUPID MISTAKES!
Time complexity? Memory usage? Precision error?
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9760 KB |
Output is correct |
5 |
Correct |
7 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
8 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
7 ms |
9812 KB |
Output is correct |
11 |
Correct |
8 ms |
9812 KB |
Output is correct |
12 |
Correct |
6 ms |
9812 KB |
Output is correct |
13 |
Correct |
8 ms |
9812 KB |
Output is correct |
14 |
Correct |
7 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9692 KB |
Output is correct |
3 |
Correct |
91 ms |
27488 KB |
Output is correct |
4 |
Correct |
73 ms |
24012 KB |
Output is correct |
5 |
Correct |
122 ms |
22740 KB |
Output is correct |
6 |
Correct |
130 ms |
24212 KB |
Output is correct |
7 |
Correct |
126 ms |
23144 KB |
Output is correct |
8 |
Correct |
143 ms |
24968 KB |
Output is correct |
9 |
Correct |
92 ms |
24828 KB |
Output is correct |
10 |
Correct |
76 ms |
29672 KB |
Output is correct |
11 |
Correct |
103 ms |
29024 KB |
Output is correct |
12 |
Correct |
90 ms |
23780 KB |
Output is correct |
13 |
Correct |
71 ms |
23724 KB |
Output is correct |
14 |
Correct |
73 ms |
24408 KB |
Output is correct |
15 |
Correct |
93 ms |
29560 KB |
Output is correct |
16 |
Correct |
67 ms |
29860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
108 ms |
26160 KB |
Output is correct |
3 |
Correct |
126 ms |
25172 KB |
Output is correct |
4 |
Correct |
108 ms |
24264 KB |
Output is correct |
5 |
Correct |
67 ms |
23752 KB |
Output is correct |
6 |
Correct |
110 ms |
24596 KB |
Output is correct |
7 |
Correct |
83 ms |
30516 KB |
Output is correct |
8 |
Correct |
79 ms |
30400 KB |
Output is correct |
9 |
Correct |
55 ms |
29588 KB |
Output is correct |
10 |
Correct |
98 ms |
24168 KB |
Output is correct |
11 |
Correct |
68 ms |
25304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
118 ms |
25160 KB |
Output is correct |
3 |
Correct |
111 ms |
25812 KB |
Output is correct |
4 |
Correct |
108 ms |
23596 KB |
Output is correct |
5 |
Correct |
110 ms |
27044 KB |
Output is correct |
6 |
Correct |
103 ms |
25292 KB |
Output is correct |
7 |
Correct |
75 ms |
30404 KB |
Output is correct |
8 |
Correct |
52 ms |
28976 KB |
Output is correct |
9 |
Correct |
49 ms |
18428 KB |
Output is correct |
10 |
Correct |
82 ms |
23584 KB |
Output is correct |
11 |
Correct |
74 ms |
24024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9760 KB |
Output is correct |
5 |
Correct |
7 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
8 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
7 ms |
9812 KB |
Output is correct |
11 |
Correct |
8 ms |
9812 KB |
Output is correct |
12 |
Correct |
6 ms |
9812 KB |
Output is correct |
13 |
Correct |
8 ms |
9812 KB |
Output is correct |
14 |
Correct |
7 ms |
9812 KB |
Output is correct |
15 |
Correct |
6 ms |
9684 KB |
Output is correct |
16 |
Correct |
7 ms |
9692 KB |
Output is correct |
17 |
Correct |
91 ms |
27488 KB |
Output is correct |
18 |
Correct |
73 ms |
24012 KB |
Output is correct |
19 |
Correct |
122 ms |
22740 KB |
Output is correct |
20 |
Correct |
130 ms |
24212 KB |
Output is correct |
21 |
Correct |
126 ms |
23144 KB |
Output is correct |
22 |
Correct |
143 ms |
24968 KB |
Output is correct |
23 |
Correct |
92 ms |
24828 KB |
Output is correct |
24 |
Correct |
76 ms |
29672 KB |
Output is correct |
25 |
Correct |
103 ms |
29024 KB |
Output is correct |
26 |
Correct |
90 ms |
23780 KB |
Output is correct |
27 |
Correct |
71 ms |
23724 KB |
Output is correct |
28 |
Correct |
73 ms |
24408 KB |
Output is correct |
29 |
Correct |
93 ms |
29560 KB |
Output is correct |
30 |
Correct |
67 ms |
29860 KB |
Output is correct |
31 |
Correct |
6 ms |
9684 KB |
Output is correct |
32 |
Correct |
108 ms |
26160 KB |
Output is correct |
33 |
Correct |
126 ms |
25172 KB |
Output is correct |
34 |
Correct |
108 ms |
24264 KB |
Output is correct |
35 |
Correct |
67 ms |
23752 KB |
Output is correct |
36 |
Correct |
110 ms |
24596 KB |
Output is correct |
37 |
Correct |
83 ms |
30516 KB |
Output is correct |
38 |
Correct |
79 ms |
30400 KB |
Output is correct |
39 |
Correct |
55 ms |
29588 KB |
Output is correct |
40 |
Correct |
98 ms |
24168 KB |
Output is correct |
41 |
Correct |
68 ms |
25304 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
118 ms |
25160 KB |
Output is correct |
44 |
Correct |
111 ms |
25812 KB |
Output is correct |
45 |
Correct |
108 ms |
23596 KB |
Output is correct |
46 |
Correct |
110 ms |
27044 KB |
Output is correct |
47 |
Correct |
103 ms |
25292 KB |
Output is correct |
48 |
Correct |
75 ms |
30404 KB |
Output is correct |
49 |
Correct |
52 ms |
28976 KB |
Output is correct |
50 |
Correct |
49 ms |
18428 KB |
Output is correct |
51 |
Correct |
82 ms |
23584 KB |
Output is correct |
52 |
Correct |
74 ms |
24024 KB |
Output is correct |
53 |
Correct |
7 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9732 KB |
Output is correct |
55 |
Correct |
6 ms |
9708 KB |
Output is correct |
56 |
Correct |
6 ms |
9812 KB |
Output is correct |
57 |
Correct |
7 ms |
9812 KB |
Output is correct |
58 |
Correct |
6 ms |
9812 KB |
Output is correct |
59 |
Correct |
6 ms |
9812 KB |
Output is correct |
60 |
Correct |
6 ms |
9812 KB |
Output is correct |
61 |
Correct |
6 ms |
9812 KB |
Output is correct |
62 |
Correct |
6 ms |
9812 KB |
Output is correct |
63 |
Correct |
7 ms |
9864 KB |
Output is correct |
64 |
Correct |
6 ms |
9824 KB |
Output is correct |
65 |
Correct |
6 ms |
9840 KB |
Output is correct |
66 |
Correct |
8 ms |
9812 KB |
Output is correct |
67 |
Correct |
83 ms |
28600 KB |
Output is correct |
68 |
Correct |
59 ms |
24336 KB |
Output is correct |
69 |
Correct |
98 ms |
23248 KB |
Output is correct |
70 |
Correct |
103 ms |
24592 KB |
Output is correct |
71 |
Correct |
115 ms |
22972 KB |
Output is correct |
72 |
Correct |
104 ms |
24384 KB |
Output is correct |
73 |
Correct |
87 ms |
24736 KB |
Output is correct |
74 |
Correct |
69 ms |
30028 KB |
Output is correct |
75 |
Correct |
79 ms |
30232 KB |
Output is correct |
76 |
Correct |
69 ms |
24100 KB |
Output is correct |
77 |
Correct |
56 ms |
23676 KB |
Output is correct |
78 |
Correct |
67 ms |
23660 KB |
Output is correct |
79 |
Correct |
80 ms |
31132 KB |
Output is correct |
80 |
Correct |
55 ms |
32020 KB |
Output is correct |
81 |
Correct |
101 ms |
24948 KB |
Output is correct |
82 |
Correct |
107 ms |
25696 KB |
Output is correct |
83 |
Correct |
105 ms |
22608 KB |
Output is correct |
84 |
Correct |
57 ms |
24476 KB |
Output is correct |
85 |
Correct |
102 ms |
27376 KB |
Output is correct |
86 |
Correct |
76 ms |
33196 KB |
Output is correct |
87 |
Correct |
87 ms |
33084 KB |
Output is correct |
88 |
Correct |
113 ms |
22960 KB |
Output is correct |
89 |
Correct |
69 ms |
23172 KB |
Output is correct |
90 |
Correct |
108 ms |
23236 KB |
Output is correct |
91 |
Correct |
119 ms |
26624 KB |
Output is correct |
92 |
Correct |
123 ms |
27140 KB |
Output is correct |
93 |
Correct |
110 ms |
26060 KB |
Output is correct |
94 |
Correct |
104 ms |
24536 KB |
Output is correct |
95 |
Correct |
80 ms |
31040 KB |
Output is correct |
96 |
Correct |
62 ms |
27940 KB |
Output is correct |
97 |
Correct |
48 ms |
17508 KB |
Output is correct |
98 |
Correct |
58 ms |
22812 KB |
Output is correct |
99 |
Correct |
76 ms |
24548 KB |
Output is correct |
100 |
Correct |
35 ms |
13260 KB |
Output is correct |
101 |
Correct |
117 ms |
26996 KB |
Output is correct |
102 |
Correct |
91 ms |
23140 KB |
Output is correct |
103 |
Correct |
89 ms |
23292 KB |
Output is correct |
104 |
Correct |
124 ms |
23852 KB |
Output is correct |