#include <bits/stdc++.h>
using namespace std;
#define nyahalo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define otsumiko exit(0);
#define mikodanye priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > >
#define mikochi priority_queue<long long, vector<long long>, greater<long long> >
long long n, m, s[200069], a, b, vd[200069], cs, nov, nn, cv, cn, sb2 = 1, tn, pv[200069], dp[200069], z[200069], pi;
vector<long long> al[200069];
mikodanye pq;
void dfs(long long cn, long long pn) {
long long i, j, nn;
pv[cn] = pn;
dp[cn] = s[cn];
for (i=0; i<al[cn].size(); i++) {
nn = al[cn][i];
if (nn == pn) {
continue;
}
dfs(nn, cn);
dp[cn] += dp[nn];
}
}
int main() {
nyahalo
long long i, j;
cin >> n >> m;
for (i=1; i<=n; i++) {
cin >> s[i];
if (i>1) {
if (s[i]>s[i-1]) {
sb2 = 0;
}
}
}
for (i=1; i<=m; i++) {
cin >> a >> b;
al[a].push_back(b);
al[b].push_back(a);
}
for (i=2; i<=n; i++) {
tn = 0;
for (j=0; j<al[i].size(); j++) {
cn = al[i][j];
if (cn<i) {
tn++;
}
}
if (tn != 1) {
sb2 = 0;
break;
}
}
if (n<=2000 && m<=2000) {
for (i=1; i<=n; i++) {
for (j=1; j<=n; j++) {
vd[j] = 0;
}
nov = 0;
cs = 0;
pq.push(make_pair(s[i], i));
vd[i] = 1;
for (; !pq.empty(); ) {
cv = pq.top().first;
cn = pq.top().second;
pq.pop();
if (cs<cv && cn != i) {
break;
}
nov++;
cs += cv;
for (j=0; j<al[cn].size(); j++) {
nn = al[cn][j];
if (vd[nn] == 0) {
vd[nn] = 1;
pq.push(make_pair(s[nn], nn));
}
}
}
for (; !pq.empty(); ) {
pq.pop();
}
if (nov == n) {
cout << "1";
} else {
cout << "0";
}
}
cout << "\n";
otsumiko
}
if (sb2 == 1) {
dfs(1, -1);
z[1] = 1;
for (i=2; i<=n; i++) {
pi = pv[i];
if (dp[i]>=s[pi] && z[pi] == 1) {
z[i] = 1;
} else {
z[i] = 0;
}
}
for (i=1; i<=n; i++) {
cout << z[i];
}
cout << "\n";
otsumiko
}
cout << "sabar deck\n";
otsumiko
}
Compilation message
island.cpp: In function 'void dfs(long long int, long long int)':
island.cpp:17:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (i=0; i<al[cn].size(); i++) {
| ~^~~~~~~~~~~~~~
island.cpp:14:16: warning: unused variable 'j' [-Wunused-variable]
14 | long long i, j, nn;
| ^
island.cpp: In function 'int main()':
island.cpp:46:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (j=0; j<al[i].size(); j++) {
| ~^~~~~~~~~~~~~
island.cpp:75:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (j=0; j<al[cn].size(); j++) {
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
162 ms |
5144 KB |
Output is correct |
5 |
Correct |
157 ms |
5176 KB |
Output is correct |
6 |
Correct |
215 ms |
5164 KB |
Output is correct |
7 |
Correct |
162 ms |
5176 KB |
Output is correct |
8 |
Correct |
112 ms |
5152 KB |
Output is correct |
9 |
Correct |
262 ms |
5200 KB |
Output is correct |
10 |
Correct |
68 ms |
5076 KB |
Output is correct |
11 |
Correct |
65 ms |
5076 KB |
Output is correct |
12 |
Correct |
75 ms |
5176 KB |
Output is correct |
13 |
Correct |
122 ms |
5140 KB |
Output is correct |
14 |
Correct |
96 ms |
5152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
131 ms |
23632 KB |
Output is correct |
4 |
Correct |
124 ms |
26760 KB |
Output is correct |
5 |
Correct |
142 ms |
22628 KB |
Output is correct |
6 |
Correct |
154 ms |
23172 KB |
Output is correct |
7 |
Correct |
159 ms |
23092 KB |
Output is correct |
8 |
Correct |
147 ms |
23164 KB |
Output is correct |
9 |
Correct |
129 ms |
24380 KB |
Output is correct |
10 |
Correct |
94 ms |
22852 KB |
Output is correct |
11 |
Correct |
87 ms |
22636 KB |
Output is correct |
12 |
Correct |
159 ms |
21756 KB |
Output is correct |
13 |
Correct |
122 ms |
33152 KB |
Output is correct |
14 |
Correct |
122 ms |
33268 KB |
Output is correct |
15 |
Correct |
125 ms |
34668 KB |
Output is correct |
16 |
Correct |
81 ms |
33628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
101 ms |
12872 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
110 ms |
13804 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
162 ms |
5144 KB |
Output is correct |
5 |
Correct |
157 ms |
5176 KB |
Output is correct |
6 |
Correct |
215 ms |
5164 KB |
Output is correct |
7 |
Correct |
162 ms |
5176 KB |
Output is correct |
8 |
Correct |
112 ms |
5152 KB |
Output is correct |
9 |
Correct |
262 ms |
5200 KB |
Output is correct |
10 |
Correct |
68 ms |
5076 KB |
Output is correct |
11 |
Correct |
65 ms |
5076 KB |
Output is correct |
12 |
Correct |
75 ms |
5176 KB |
Output is correct |
13 |
Correct |
122 ms |
5140 KB |
Output is correct |
14 |
Correct |
96 ms |
5152 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
131 ms |
23632 KB |
Output is correct |
18 |
Correct |
124 ms |
26760 KB |
Output is correct |
19 |
Correct |
142 ms |
22628 KB |
Output is correct |
20 |
Correct |
154 ms |
23172 KB |
Output is correct |
21 |
Correct |
159 ms |
23092 KB |
Output is correct |
22 |
Correct |
147 ms |
23164 KB |
Output is correct |
23 |
Correct |
129 ms |
24380 KB |
Output is correct |
24 |
Correct |
94 ms |
22852 KB |
Output is correct |
25 |
Correct |
87 ms |
22636 KB |
Output is correct |
26 |
Correct |
159 ms |
21756 KB |
Output is correct |
27 |
Correct |
122 ms |
33152 KB |
Output is correct |
28 |
Correct |
122 ms |
33268 KB |
Output is correct |
29 |
Correct |
125 ms |
34668 KB |
Output is correct |
30 |
Correct |
81 ms |
33628 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Incorrect |
101 ms |
12872 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |