#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using ld = long double;
void solve(int T);
void pre();
const int N = 1e5 + 5;
const int M = 405;
const int SQRT = 500;
const int LOG = 20;
const int INF = 1e18;
const int MOD = 1e9+7;
const ld EPS = 1e-9;
void pre(){
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
}
int32_t main(){
pre();
int tt = 1;
//cin>>tt;
for(int i = 1;i<=tt;i++){
//cerr<<"Case "<<i<<": "<<endl;
solve(i);
}
return 0;
}
int A[N];
vector<int> g[N];
bool vis[N];
int sum = 0;
vector<int> cur;
int xx;
void dfs(int x){
vis[x] = true;
sum += A[x];
cur.pb(x);
for(auto p: g[x]){
if(vis[p])continue;
if(A[p] <= xx)dfs(p);
}
}
void solve(int T){
int n,m;
cin>>n>>m;
set<int> s;
for(int i = 1;i<=n;i++){
cin>>A[i];
s.insert(A[i]);
}
for(int i = 0;i<m;i++){
int a,b;
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
bool ok[n+1];
memset(ok, 1, sizeof ok);
int z = s.size();
for(int i = 0;i < z - 1;i++){
if(s.empty())break;
auto in = *(s.begin());
s.erase(in);
if(s.empty())break;
xx = in;
for(int j = 1;j<=n;j++){
for(auto p : g[j]){
if(A[j] == i || A[p] == i){
g[p].pb(j);
g[j].pb(p);
}
}
}
memset(vis, 0, sizeof vis);
for(int j = 1;j<=n;j++){
if(!vis[j] && A[j] <= xx){
sum = 0;
cur.clear();
dfs(j);
if(sum < *(s.begin())){
for(auto p : cur){
ok[p] = false;
}
}
}
}
}
for(int i = 1;i<=n;i++)cout<< ok[i];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Runtime error |
3 ms |
5468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
5464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Runtime error |
53 ms |
16412 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Runtime error |
31 ms |
6736 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Runtime error |
3 ms |
5468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |