#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define st first
#define nd second
typedef long long ll;
ll f(vector<ll>&u,ll i)
{
if(u[i]==i)
{
return i;
}
u[i]=f(u,u[i]);
return u[i];
}
void f2(vector<ll>&u,vector<ll>&w,ll i)
{
if(u[i]==i)
{
w[i]=2;
return;
}
if(w[i]>0)
{
return;
}
f2(u,w,u[i]);
w[i]=w[u[i]];
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);
ll n,m;
cin>>n>>m;
vector<ll>a(n);
vector<pair<ll,ll>>c(n);
vector<vector<ll>>b(n);
vector<ll>d(n);
for(ll i=0;i<n;i++)
{
cin>>c[i].st;
c[i].nd=i;
a[i]=c[i].st;
d[i]=a[i];
}
sort(all(c));
for(ll i=0;i<m;i++)
{
ll x,y;
cin>>x>>y;
b[x-1].push_back(y-1);
b[y-1].push_back(x-1);
}
vector<ll>u1(n);
vector<ll>u2(n);
vector<bool>wyn(n,false);
for(ll i=0;i<n;i++)
{
u1[i]=i;
u2[i]=i;
}
for(ll q=0;q<n;q++)
{
ll i=c[q].nd;
ll wag=0;
for(ll j=0;j<b[i].size();j++)
{
if(a[b[i][j]]<a[i] or (a[b[i][j]]==a[i] && i>b[i][j]))
{
if(d[f(u1,b[i][j])]<a[i])
{
wyn[f(u1,b[i][j])]=true;
}
wag+=d[u1[b[i][j]]];
u2[u1[b[i][j]]]=i;
u1[u1[b[i][j]]]=i;
}
}
d[i]+=wag;
}
vector<ll>ww(n);
for(ll i=0;i<n;i++)
{
ww[i]=wyn[i];
}
for(ll i=0;i<n;i++)
{
if(ww[i]==0)
{
f2(u2,ww,i);
}
cout<<ww[i]-1;
}
cout<<endl;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:66:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(ll j=0;j<b[i].size();j++)
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
88 ms |
27604 KB |
Output is correct |
4 |
Correct |
90 ms |
32336 KB |
Output is correct |
5 |
Correct |
94 ms |
26960 KB |
Output is correct |
6 |
Correct |
98 ms |
27732 KB |
Output is correct |
7 |
Correct |
95 ms |
27880 KB |
Output is correct |
8 |
Correct |
119 ms |
34200 KB |
Output is correct |
9 |
Correct |
90 ms |
29036 KB |
Output is correct |
10 |
Correct |
77 ms |
27540 KB |
Output is correct |
11 |
Correct |
101 ms |
33852 KB |
Output is correct |
12 |
Correct |
101 ms |
27220 KB |
Output is correct |
13 |
Correct |
75 ms |
31568 KB |
Output is correct |
14 |
Correct |
80 ms |
31312 KB |
Output is correct |
15 |
Correct |
81 ms |
26964 KB |
Output is correct |
16 |
Correct |
63 ms |
25940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
100 ms |
26556 KB |
Output is correct |
3 |
Correct |
104 ms |
26960 KB |
Output is correct |
4 |
Correct |
110 ms |
33296 KB |
Output is correct |
5 |
Correct |
73 ms |
29524 KB |
Output is correct |
6 |
Correct |
102 ms |
26960 KB |
Output is correct |
7 |
Correct |
89 ms |
27048 KB |
Output is correct |
8 |
Correct |
89 ms |
26896 KB |
Output is correct |
9 |
Correct |
59 ms |
26072 KB |
Output is correct |
10 |
Correct |
77 ms |
29268 KB |
Output is correct |
11 |
Correct |
84 ms |
26452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
121 ms |
27900 KB |
Output is correct |
3 |
Correct |
113 ms |
27984 KB |
Output is correct |
4 |
Correct |
117 ms |
27988 KB |
Output is correct |
5 |
Correct |
110 ms |
27988 KB |
Output is correct |
6 |
Correct |
100 ms |
27732 KB |
Output is correct |
7 |
Correct |
76 ms |
31808 KB |
Output is correct |
8 |
Correct |
72 ms |
30552 KB |
Output is correct |
9 |
Incorrect |
70 ms |
16724 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
88 ms |
27604 KB |
Output is correct |
18 |
Correct |
90 ms |
32336 KB |
Output is correct |
19 |
Correct |
94 ms |
26960 KB |
Output is correct |
20 |
Correct |
98 ms |
27732 KB |
Output is correct |
21 |
Correct |
95 ms |
27880 KB |
Output is correct |
22 |
Correct |
119 ms |
34200 KB |
Output is correct |
23 |
Correct |
90 ms |
29036 KB |
Output is correct |
24 |
Correct |
77 ms |
27540 KB |
Output is correct |
25 |
Correct |
101 ms |
33852 KB |
Output is correct |
26 |
Correct |
101 ms |
27220 KB |
Output is correct |
27 |
Correct |
75 ms |
31568 KB |
Output is correct |
28 |
Correct |
80 ms |
31312 KB |
Output is correct |
29 |
Correct |
81 ms |
26964 KB |
Output is correct |
30 |
Correct |
63 ms |
25940 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
100 ms |
26556 KB |
Output is correct |
33 |
Correct |
104 ms |
26960 KB |
Output is correct |
34 |
Correct |
110 ms |
33296 KB |
Output is correct |
35 |
Correct |
73 ms |
29524 KB |
Output is correct |
36 |
Correct |
102 ms |
26960 KB |
Output is correct |
37 |
Correct |
89 ms |
27048 KB |
Output is correct |
38 |
Correct |
89 ms |
26896 KB |
Output is correct |
39 |
Correct |
59 ms |
26072 KB |
Output is correct |
40 |
Correct |
77 ms |
29268 KB |
Output is correct |
41 |
Correct |
84 ms |
26452 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
121 ms |
27900 KB |
Output is correct |
44 |
Correct |
113 ms |
27984 KB |
Output is correct |
45 |
Correct |
117 ms |
27988 KB |
Output is correct |
46 |
Correct |
110 ms |
27988 KB |
Output is correct |
47 |
Correct |
100 ms |
27732 KB |
Output is correct |
48 |
Correct |
76 ms |
31808 KB |
Output is correct |
49 |
Correct |
72 ms |
30552 KB |
Output is correct |
50 |
Incorrect |
70 ms |
16724 KB |
Output isn't correct |
51 |
Halted |
0 ms |
0 KB |
- |