#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fore(i , n) for(int i = 0 ; i<n;i++)
#define forr(i , x , y) for(int i = x ; i <= y; i++)
#define forn(i , x , y) for(int i = x ; i >= y; i--)
const int N = 2e5 + 10;
vector<int> adj[N];
int a[N];
vector<bool> marked(N , 0);
int n , m;
vector<bool> mrigl(N , 0);
void expand(int x)
{
priority_queue<pair<int ,int> , vector<pair<int ,int>> , greater<pair<int , int>>> pq;
int cur = a[x];
vector<bool> vis(n , 0);
pq.push({cur , x});
vector<int> possible;
while(!pq.empty())
{
auto [val , node] = pq.top();
pq.pop();
if(val >= cur)
{
possible.pb(node);
}
if(val > cur)
continue;
if(vis[node])
continue;
vis[node] = 1;
if(node != x)
cur+=val;
for(auto u : adj[node])
{
pq.push({a[u] , u});
}
}
bool acc = 1;
fore(i , n)
{
if(!vis[i])
{
acc = 0;
break;
}
}
if(acc)
{
for(auto u : possible)
mrigl[u] = 1;
cout<<1;
}
else
{
fore(i , n)
{
if(vis[i])
marked[i] = 1;
}
cout<<0;
}
}
signed main()
{
cin>>n>>m;
fore(i , n)
cin>>a[i];
fore(i , m)
{
int u , v;
cin>>u>>v;
u-- , v--;
adj[u].pb(v);
adj[v].pb(u);
}
fore(i , n)
{
if(marked[i])
{
cout<<0;
}
else if(mrigl[i])
{
cout<<1;
}
else
expand(i);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
304 ms |
6644 KB |
Output is correct |
5 |
Correct |
228 ms |
6492 KB |
Output is correct |
6 |
Correct |
271 ms |
6492 KB |
Output is correct |
7 |
Correct |
306 ms |
6668 KB |
Output is correct |
8 |
Correct |
236 ms |
6656 KB |
Output is correct |
9 |
Correct |
4 ms |
6492 KB |
Output is correct |
10 |
Correct |
132 ms |
6492 KB |
Output is correct |
11 |
Correct |
119 ms |
6628 KB |
Output is correct |
12 |
Correct |
97 ms |
6652 KB |
Output is correct |
13 |
Correct |
4 ms |
6492 KB |
Output is correct |
14 |
Correct |
24 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Execution timed out |
1036 ms |
18076 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
12864 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Execution timed out |
1078 ms |
14248 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
304 ms |
6644 KB |
Output is correct |
5 |
Correct |
228 ms |
6492 KB |
Output is correct |
6 |
Correct |
271 ms |
6492 KB |
Output is correct |
7 |
Correct |
306 ms |
6668 KB |
Output is correct |
8 |
Correct |
236 ms |
6656 KB |
Output is correct |
9 |
Correct |
4 ms |
6492 KB |
Output is correct |
10 |
Correct |
132 ms |
6492 KB |
Output is correct |
11 |
Correct |
119 ms |
6628 KB |
Output is correct |
12 |
Correct |
97 ms |
6652 KB |
Output is correct |
13 |
Correct |
4 ms |
6492 KB |
Output is correct |
14 |
Correct |
24 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Execution timed out |
1036 ms |
18076 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |