#include <bits/stdc++.h>
#define int long long
//#define endl '\n'
using namespace std;
const int MAX = 2e5 + 5;
vector<int> adj[MAX];
int color[MAX], sum[MAX];
int s[MAX], ans[MAX];
void bfs(int st){
sum[st] = s[st];
color[st] = 1;
queue<int> q;
q.push(st);
while (!q.empty())
{
int u = q.front();
q.pop();
vector<pair<int, int>> d;
for(auto v : adj[u]){
if(!color[v]) d.push_back({s[v], v});
}
sort(d.begin(), d.end());
for(auto i : d){
if(i.first <= sum[st]){
color[i.second] = 1;
q.push(i.second);
sum[st] += i.first;
}
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin>>n>>m;
int total = 0;
for(int i = 1; i <= n; i++) cin>>s[i], total += s[i];
for (int i = 1; i <= m; i++)
{
int u, v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; i++){
memset(color, 0, sizeof(color));
bfs(i);
if(sum[i] == total) cout<<1;
else cout<<0;
}
cout<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6516 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Incorrect |
175 ms |
6684 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Execution timed out |
1081 ms |
15472 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6484 KB |
Output is correct |
2 |
Execution timed out |
1076 ms |
14368 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Execution timed out |
1078 ms |
15424 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6516 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
3 ms |
6484 KB |
Output is correct |
4 |
Incorrect |
175 ms |
6684 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |