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;
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 |
---|
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... |