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 <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int MAX = 2e5 + 5;
int n, m;
int arr[MAX];
vector<int> g[MAX];
bool visited[MAX];
bool bfs(int start){
fill(visited, visited + n + 1, 0);
ll cnt = 0;
set<pii> q;
q.insert({arr[start], start});
while(!q.empty()){
int node = q.begin()->second;
int c = q.begin()->first;
q.erase(q.begin());
visited[node] = true;
if(cnt >= c || node == start){
cnt += c;
for(int to:g[node]){
if(visited[to]) continue;
q.insert({arr[to], to});
}
}
else{
return false;
}
}
return true;
}
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
for (int i = 0; i < m; i++)
{
int a, b; cin >> a >> b;
g[a].emplace_back(b);
g[b].emplace_back(a);
}
if(n > 2000 || m > 2000){
cout << 1;
for (int i = 2; i <= n; i++)
{
cout << (arr[i] == arr[1]);
}
return 0;
}
for (int i = 1; i <= n; i++)
{
cout << bfs(i);
}
}
# | 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... |