#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100001];
int vis[100001];
long long sum = 0 , cn = 0;
void dfs(int i){
cn++;
vis[i] = 1;
sum+=adj[i].size();
for(auto j:adj[i]){
if(vis[j])continue;
dfs(j);
}
}
int main(){
int n,m;cin>>n>>m;
map<pair<int,int>,int> mp;
int ans = 0;
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
if(x==y)continue;
if(x>y)swap(x,y);
if(mp[{x,y}]==1)continue;
mp[{x,y}] = 1;
ans++;
adj[x].push_back(y);
}
if(ans==n*(n-1)/2){
cout<<"DA\n";
return 0;
}
int cnt = 0;
bool ss = 1;
for(int i = 1;i<=n;i++){
if(!vis[i]){
cnt++;
cn = 0;sum = 0;
dfs(i);
if(cn*(cn-1)/2!=sum){
ss = 0;
}
}
}
if(ss&&cnt==2){
cout<<"DA\n";
}else cout<<"NE\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2656 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
3 ms |
2792 KB |
Output is correct |
4 |
Correct |
3 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
3332 KB |
Output is correct |
2 |
Correct |
50 ms |
6936 KB |
Output is correct |
3 |
Correct |
20 ms |
4216 KB |
Output is correct |
4 |
Correct |
10 ms |
3656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3028 KB |
Output is correct |
2 |
Correct |
33 ms |
5472 KB |
Output is correct |
3 |
Correct |
102 ms |
14016 KB |
Output is correct |
4 |
Correct |
163 ms |
20040 KB |
Output is correct |