답안 #640449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640449 2022-09-14T16:46:28 Z andecaandeci Stranded Far From Home (BOI22_island) C++17
0 / 100
2 ms 640 KB
#include <bits/stdc++.h>
using namespace std;

int n, m;
int v[2005];
pair<int ,int> arr[2005];
vector<int> adj[2005];

bool vis[2005];

int bfs(int start) {
    // cout << "-----------" << endl;
    priority_queue<pair<int ,int> , vector<pair<int, int> >, greater<pair<int ,int> > > pq;
    queue<int> q;
    memset(vis, 0, sizeof(vis));
    q.push(start);
    vis[start] = true;
    int cnt = 0;
    int sz = v[start];
    while(!q.empty()) {
        int cur = q.front();
        // cout << "::" << cur << endl;
        q.pop();
        for(int i = 0; i < adj[cur].size(); i++) {
            int nx = adj[cur][i];
            // cout << nx << endl;
            if (!vis[nx]) {
                vis[nx] = true;
                pq.push(make_pair(v[nx], nx));
            }
        }

        cnt++;
        // cout << "pq" << endl;
        while (!pq.empty() && pq.top().first <= sz) {
            sz += pq.top().first;
            q.push(pq.top().second);
            // cout << pq.top().second << endl;
            pq.pop();
        }
    }
    if (cnt == n) {
        return 1;
    }
    else {
        return 0;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
        arr[i].first = v[i];
        arr[i].second = i;

    }

    for(int i = 1; i <= m; i++ ) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for(int i = 1; i <= n; i++) {
        cout << bfs(i);
    }
    cout << endl;
}

Compilation message

island.cpp: In function 'int bfs(int)':
island.cpp:24:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for(int i = 0; i < adj[cur].size(); i++) {
      |                        ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Incorrect 2 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Runtime error 1 ms 596 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 596 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 640 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Incorrect 2 ms 468 KB Output isn't correct
5 Halted 0 ms 0 KB -