#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 = 2e5 + 10;
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 |
2 ms |
6748 KB |
Output is correct |
2 |
Runtime error |
6 ms |
13244 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
13144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Runtime error |
608 ms |
48760 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
396 ms |
17880 KB |
Output is correct |
3 |
Correct |
304 ms |
18712 KB |
Output is correct |
4 |
Correct |
282 ms |
18976 KB |
Output is correct |
5 |
Correct |
198 ms |
18960 KB |
Output is correct |
6 |
Correct |
192 ms |
18240 KB |
Output is correct |
7 |
Correct |
178 ms |
22216 KB |
Output is correct |
8 |
Runtime error |
160 ms |
47772 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Runtime error |
6 ms |
13244 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |