This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//github.com/nya-nya-meow/CompetitiveProgramming/blob/master/CSES/CSES%201112%20-%20Substrings.cpp
#include<bits/stdc++.h>
#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef pair<double,double>pdd;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
const double EPS= 1e-8;
const int N = 1e5+5, M = 2e5+5, OO = 0x3f3f3f3f;
int n,m,vis[2005],id,ck[5000000];
vector<int>a[2005];
void dfs(int u)
{
vis[u]=id;
for(auto v:a[u])
if(vis[v]==-1)dfs(v);
}
int main()
{
input;
cin>>n>>m;
int u,v;
forr(i,1,m)
{
cin>>u>>v;
a[u].push_back(v);
a[v].push_back(u);
}
memset(vis,-1,sizeof vis);
forr(i,1,n)
{
if(vis[i]==-1)
{
id++;
dfs(i);
}
}
set<pair<int,int>>c1,c2;
int cnt1=0,cnt2=0;
forr(i,1,n)
{
if(vis[i]==1){
cnt1++;
for(auto v:a[i])
c1.insert({min(i,v),max(i,v)});}
else if(vis[i]==2){
cnt2++;
for(auto v:a[i])
c2.insert({min(i,v),max(i,v)});}
}
for(int i=1;i<=2000;i++)ck[i]=i*(i-1)/2;
if((id==1&&ck[cnt1]==(int)c1.size())||(id==2&&ck[cnt1]==(int)c1.size()&&ck[cnt2]==(int)c2.size()))cout<<"DA"<<endl;
else cout<<"NE"<<endl;
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... |