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>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
vector <int> g[20];
int cl[20];
bool ok=1;
void dfs(int v){
cl[v]=1;
for(auto to : g[v]){
if(cl[to]==0)dfs(to);
else if(cl[to]==1)ok=0;
}
cl[v]=2;
}
signed main(){
int n,m;
cin>>n>>m;
vector <int> u(m),v(m);
for(int i=0;i<m;i++){
cin>>u[i]>>v[i];
}
int ans=0;
for(int i=0;i<(1<<m);i++){
for(int j=1;j<=n;j++){
cl[j]=0;
g[j].clear();
}
ok=1;
int cnt=0;
for(int j=0;j<m;j++){
if((i & (1<<j))){
g[v[j]].pb(u[j]);cnt++;
}
else g[u[j]].pb(v[j]);
}
for(int j=1;j<=n;j++){
if(!cl[j])dfs(j);
}
if(ok)ans+=cnt;
}
cout<<ans<<"\n";
}
/*
*/
# | 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... |