답안 #993613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993613 2024-06-06T08:33:06 Z amine_aroua Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 16784 KB
#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];
bool marked[N];
int n , m;
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});
    while(!pq.empty())
    {
        auto [val , node] = pq.top();
        pq.pop();
        if(val > cur)
            break;
        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)
    {
        cout<<1;
    }
    else
    {
        fore(i , n)
        {
            if(vis[i])
                marked[i] = 1;
        }
        cout<<0;
    }
}
int 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
            expand(i);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Incorrect 4 ms 5976 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5736 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Execution timed out 1091 ms 16660 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Execution timed out 1088 ms 16516 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Execution timed out 1068 ms 16784 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Incorrect 4 ms 5976 KB Output isn't correct
5 Halted 0 ms 0 KB -