#include<bits/stdc++.h>
using namespace std;
int n,m;
int head[500005];
int cnt = 0;
long long int a[500005];
int last[500005];
long long int siz[500005];
set<pair<long long int,int>> s;
struct edg
{
int to;
int next;
}edge[500005];
void add(int x,int y)
{
cnt++;
edge[cnt].to = y;
edge[cnt].next = head[x];
head[x] = cnt;
}
bool vis[500005];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
add(x,y);
add(y,x);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)vis[j] = false;
s.clear();
vis[i] = true; // 以i開始,做bfs;
int cnt = 0;
pair<int,int> pp = make_pair(a[i],i);
s.insert(pp);
long long int nowval = 0;
//cout<<"i "<<i<<endl;
while(s.empty() == false)
{
auto it = (*s.begin());
int id = it.second;
vis[id] = true;
//cout<<"nowval: "<<nowval<<" "<<it.second<<endl;
if(nowval >= it.first || it.second == i)nowval += it.first;
else break;
cnt++;
s.erase(s.begin());
for(int j=head[id];j!=0;j=edge[j].next)
{
int to = edge[j].to;
if(vis[to] == true)continue;
pair<int,int> nw = make_pair(a[to],to);
s.insert(nw);
}
}
if(cnt >= n)last[i] = 1;
}
for(int i=1;i<=n;i++)cout<<last[i];
cout<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
168 ms |
6624 KB |
Output is correct |
5 |
Correct |
136 ms |
6488 KB |
Output is correct |
6 |
Correct |
267 ms |
6488 KB |
Output is correct |
7 |
Correct |
173 ms |
8540 KB |
Output is correct |
8 |
Correct |
131 ms |
6648 KB |
Output is correct |
9 |
Correct |
195 ms |
6492 KB |
Output is correct |
10 |
Correct |
64 ms |
6644 KB |
Output is correct |
11 |
Correct |
61 ms |
6656 KB |
Output is correct |
12 |
Correct |
67 ms |
6488 KB |
Output is correct |
13 |
Correct |
119 ms |
6488 KB |
Output is correct |
14 |
Correct |
74 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
12460 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 |
1085 ms |
10944 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 |
1089 ms |
10944 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
168 ms |
6624 KB |
Output is correct |
5 |
Correct |
136 ms |
6488 KB |
Output is correct |
6 |
Correct |
267 ms |
6488 KB |
Output is correct |
7 |
Correct |
173 ms |
8540 KB |
Output is correct |
8 |
Correct |
131 ms |
6648 KB |
Output is correct |
9 |
Correct |
195 ms |
6492 KB |
Output is correct |
10 |
Correct |
64 ms |
6644 KB |
Output is correct |
11 |
Correct |
61 ms |
6656 KB |
Output is correct |
12 |
Correct |
67 ms |
6488 KB |
Output is correct |
13 |
Correct |
119 ms |
6488 KB |
Output is correct |
14 |
Correct |
74 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Execution timed out |
1092 ms |
12460 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |