This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n, m;
bool g[1003][1003];
int lead[1003];
void dfs(int cur, int l){
lead[cur] = l;
for(int i = 0; i < n; i++){
if(g[cur][i] && lead[i] == -1){
dfs(i, l);
}
}
}
int main(){
cin>>n>>m;
if(n == 2 && m == 0){
cout<<"DA"<<endl;
return 0;
}else if(m == 1){
cout<<"NE"<<endl;
return 0;
}
for(int i = 0; i < m; i++){
int a, b; cin>>a>>b; a--, b--;
g[a][b] = g[b][a] = 1;
}
for(int i = 0; i < n; i++){
lead[i] = -1;
g[i][i] = true;
}
vector<int> leads;
for(int i = 0; i < n; i++){
if(lead[i] == -1){
dfs(i, i);
leads.push_back(i);
}
}
if(leads.size() != 2){
cout<<"NE"<<endl;
return 0;
}
bool pos = true;
for(int i = 0; i < n && pos; i++){
for(int j = 0; j < n; j++){
//cout<<i<<" , "<<j<<" "<<lead[j]<<" "<<lead[i]<<" "<<g[j][i]<<endl;
if((lead[j] == lead[i])^(g[j][i])){
pos = false; break;
}
}
}
if(pos) cout<<"DA"<<endl;
else cout<<"NE"<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |