This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define UseOFF ios_base::sync_with_stdio(0);cin.tie(0), cout.tie(0);
#define sz size
#define ins insert
#define new junkedseduneon
#define prev usfdjik
const ll N = 2222 + 111;
ll a[N];
vector <ll> v[N];
bool used[N];
void solve() {
ll n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= m; i++) {
ll x, y;
cin >> x >> y;
v[x].pb(y);
v[y].pb(x);
}
for(int i = 1; i <= n; i++) {
multiset < pair <ll, ll> > st;
st.ins({a[i], i});
//cout << x.ff << " " << x.ss << '\n';
ll cur = 0;
bool bb = 0;
for(int j = 1; j <= n; j++) used[j] = 0;
while(st.sz() > 0) {
vector <ll> g;
pair <ll, ll> x = *st.begin();
if(cur < x.ff && x.ss != i) {
cout << '0';
bb = 1;
break;
}
cur += x.ff;
for(auto to : v[x.ss]) {
if(used[to]) continue;
//cout << i << " " << to << " " << x.ss << endl;
st.ins({a[to], to});
used[to] = 1;
}
st.erase(x);
}
if(st.sz() == 0) {
cout << '1';
}
}
}
signed main()
{
UseOFF
ll ttt = 1;
//cin >> ttt;
while(ttt--)
{
solve();
}
}
Compilation message (stderr)
island.cpp: In function 'void solve()':
island.cpp:59:8: warning: variable 'bb' set but not used [-Wunused-but-set-variable]
59 | bool bb = 0;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |