Submission #246134

# Submission time Handle Problem Language Result Execution time Memory
246134 2020-07-08T09:06:00 Z Vladikus004 Ronald (COCI17_ronald) C++14
120 / 120
45 ms 3576 KB
#include <bits/stdc++.h>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int N = 1000 + 3;
int n, m, cmp[N], cnt, ed[N], sz[N], _cnt[N];
vector <vector <int> > v;

void dfs(int x, int w){
    cmp[x] = w;
    for (auto u: v[x]){
        if (cmp[u]) continue;
        dfs(u, w);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        --x; --y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for (int i = 0; i < n; i++)
        if (!cmp[i])
            dfs(i, ++cnt);
    for (int i = 0; i < n; i++){
        ed[cmp[i]] += v[i].size();
        sz[cmp[i]]++;
    }
    if (cnt >= 3){
        cout << "NE";
        return 0;
    }
    int can = 1;
    for (int i = 1; i <= cnt; i++)
        if (ed[i] != sz[i] * (sz[i] - 1)) can = 0;
    if (can) cout << "DA";
    else cout << "NE";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 15 ms 1152 KB Output is correct
3 Correct 9 ms 640 KB Output is correct
4 Correct 8 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 11 ms 896 KB Output is correct
3 Correct 40 ms 2704 KB Output is correct
4 Correct 45 ms 3576 KB Output is correct