답안 #527868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527868 2022-02-18T14:24:51 Z aris12345678 Deblo (COCI18_deblo) C++14
18 / 90
1000 ms 8480 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1e5+5;
vector<int> adj[mxN];
int a[mxN], res[mxN];

void bfs(int s) {
    queue<int> q;
    res[s] = a[s];
    q.push(s);
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        for(auto &v : adj[u]) {
            if(res[v] == -1) {
                res[v] = res[u]^a[v];
                q.push(v);
            }
        }
    }
}

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for(int i = 1; i < n; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        adj[u-1].push_back(v-1);
        adj[v-1].push_back(u-1);
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++)
            res[j] = -1;
        bfs(i);
        for(int j = i; j < n; j++)
            ans += res[j];
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

deblo.cpp: In function 'int main()':
deblo.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
deblo.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
deblo.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Incorrect 2 ms 2640 KB Output isn't correct
4 Incorrect 14 ms 2704 KB Output isn't correct
5 Incorrect 15 ms 2704 KB Output isn't correct
6 Execution timed out 1062 ms 8388 KB Time limit exceeded
7 Execution timed out 1045 ms 8324 KB Time limit exceeded
8 Execution timed out 1033 ms 8448 KB Time limit exceeded
9 Execution timed out 1040 ms 8432 KB Time limit exceeded
10 Execution timed out 1051 ms 8480 KB Time limit exceeded