Submission #109129

# Submission time Handle Problem Language Result Execution time Memory
109129 2019-05-04T15:18:57 Z bibabas Ronald (COCI17_ronald) C++14
0 / 120
70 ms 6264 KB
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair

int INF = (int)2e9;

using namespace std;

template <class T>
istream& operator >>(istream &in, vector<T> &arr) {
    for (T &cnt : arr) {
        in >> cnt;
    }
    return in;
};

int matr[1000][1000];
bool visited[1000];
int state[1000];
bool kek1 = true, kek2 = true;
int n;

void dfs(int v, int k, bool & kek){
    visited[v] = true;
    for (int i = 0; i < n; ++i){
        if (i != v) {
            if (matr[i][v]) {
                if (state[i] == k ^ 1)
                    kek = false;
                state[i] = k;
                if (!visited[i])
                    dfs(i, k ^ 1, kek);
            }
            if (!matr[v][i]) {
                if (state[i] == k)
                    kek = false;
                state[i] = k ^ 1;
                if (!visited[i])
                    dfs(i, k ^ 1, kek);
            }
        }
    }
}
void solve() {
    memset(visited, false, sizeof(visited));
    memset(state, -1, sizeof(state));
    int m; cin >> n >> m;
    for (int j = 0; j < m; ++j){
        int v, u; cin >> v >> u;
        matr[v - 1][u - 1] = 1;
        matr[u - 1][v - 1] = 1;
    }
    dfs(0, 0, kek1);
    dfs(0, 1, kek2);
    if (!kek1 && !kek2)
        cout << "NE";
    else
        cout << "DA";
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#endif

    solve();

    return 0;
}

Compilation message

ronald.cpp: In function 'void dfs(int, int, bool&)':
ronald.cpp:35:30: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
                 if (state[i] == k ^ 1)
                     ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Incorrect 3 ms 640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 29 ms 2688 KB Output is correct
3 Correct 62 ms 5624 KB Output is correct
4 Incorrect 70 ms 6264 KB Output isn't correct