Submission #714636

# Submission time Handle Problem Language Result Execution time Memory
714636 2023-03-25T06:58:29 Z ismayil Stranded Far From Home (BOI22_island) C++17
0 / 100
1000 ms 13176 KB
#include <bits/stdc++.h>
#define ll 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];
bool bfs(int st){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.push(make_pair(s[st], st));
    sum[st] = s[st];
    while (!q.empty())
    {
        int u = q.top().second;
        int w = q.top().first;
        q.pop();
        color[u] = 1;
        if(w > sum[st]) return false;
        if(st != u) sum[st] += w;
        for(auto v : adj[u]){
            if(!color[v]) q.push({s[v], v});
        }
        
    }
    return true;
}
int 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];
    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));
        cout<<bfs(i);
    }
    cout<<endl;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:34:9: warning: unused variable 'total' [-Wunused-variable]
   34 |     int total = 0;
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 4 ms 5784 KB Output is correct
4 Incorrect 42 ms 5864 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5716 KB Output is correct
2 Correct 4 ms 5716 KB Output is correct
3 Execution timed out 1094 ms 13176 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Execution timed out 1070 ms 13112 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5716 KB Output is correct
2 Execution timed out 1075 ms 13164 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 4 ms 5784 KB Output is correct
4 Incorrect 42 ms 5864 KB Output isn't correct
5 Halted 0 ms 0 KB -