#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector <string> vs;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector <pii> vpii;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define endl "\n"
#define MAX_N static_cast<ll>(1e3+5)
vi adj[MAX_N];
int comp[MAX_N];
int comp_size[MAX_N];
bool visited[MAX_N];
int comp_cnt = 0;
void dfs(int start) {
visited[start] = true;
comp[start] = comp_cnt;
comp_size[comp_cnt]++;
for(int a: adj[start]) {
if(!visited[a]) dfs(a);
}
}
int out(int res) {
if(res) {
cout << "DA" << endl;
} else {
cout << "NE" << endl;
}
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int m;
cin >> m;
vpii edges;
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
edges.pb({a, b});
}
for(int i = 1; i <= n; i++) {
if(!visited[i]) {
dfs(i);
comp_cnt++;
if(comp_cnt>2) break;
}
}
if(comp_cnt!=2) return out(0);
vi comp_edges(MAX_N);
for(int i = 0; i < m; i++) {
comp_edges[comp[edges[i].first]]++;
}
if((comp_size[0] * (comp_size[0]-1))/2==comp_edges[0] && (comp_size[1] * (comp_size[1]-1))/2==comp_edges[1]) {
return out(1);
} else {
return out(0);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
480 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
488 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
7 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
1368 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
608 KB |
Output is correct |
2 |
Correct |
4 ms |
1732 KB |
Output is correct |
3 |
Correct |
17 ms |
5428 KB |
Output is correct |
4 |
Correct |
29 ms |
7704 KB |
Output is correct |