Submission #469441

# Submission time Handle Problem Language Result Execution time Memory
469441 2021-09-01T01:55:34 Z julian33 Ronald (COCI17_ronald) C++14
120 / 120
50 ms 6160 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif

#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=1e3+5; //make sure this is right
const int mod=1e9+7;

int adj[mxN][mxN];

struct DSU{
    int uf[mxN];
    void init(){memset(uf,-1,sizeof(uf));}
    int find(int x){return uf[x]<0?x:uf[x]=find(uf[x]);}
    bool same(int x,int y){return find(x)==find(y);}
    void unite(int x,int y){
        x=find(x); y=find(y);
        if(x==y)
            return;
        if(uf[x]>uf[y])
            swap(x,y);
        uf[x]+=uf[y]; uf[y]=x;
    }   
} dsu;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    dsu.init();
    int n,m; cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b; cin>>a>>b;
        adj[a][b]=1; adj[b][a]=1;
        dsu.unite(a,b);
    }
    set<int> diff;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i==j)
                continue;
            if(!adj[i][j] && dsu.same(i,j)){
                cout<<"NE\n";
                return 0;
            }
        }
        diff.insert(dsu.find(i));
    }
    if(sz(diff)<=2){
        cout<<"DA\n";
    } else{
        cout<<"NE\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1100 KB Output is correct
2 Correct 13 ms 2672 KB Output is correct
3 Correct 5 ms 1612 KB Output is correct
4 Correct 4 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 9 ms 2508 KB Output is correct
3 Correct 32 ms 5396 KB Output is correct
4 Correct 50 ms 6160 KB Output is correct