#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
unsigned long long n;
int m;
int main()
{
cin>>n>>m;
vector<pair<int,int>> rozk(m);
for (int i=0; i<m; i++){
cin>>rozk[i].F>>rozk[i].S;
}
unsigned long long bound=1<<n;
vector<bool>wyn(n+1,0);
for (unsigned long long i=1; i<bound; i++){
long long l1=__builtin_popcountll(i);
vector<bool> szereg(n+1,0);
for (unsigned long long j=0;j<n;j++){
if((i&(1<<j))!=0)
szereg[j+1]=1;
}
for(auto edg : rozk){
if(szereg[edg.F]&&!szereg[edg.S]){
szereg[edg.F]=0;
szereg[edg.S]=1;
}
}
bool flst=0,flend=0,flzle=0;
for (long long i=1; i<=n; i++){
if(szereg[i]&&!flst)
flst=1;
if(flst&&!szereg[i]){
flend=1;
}
if(flend&&szereg[i]){
flzle=1;
}
}
if(!flzle){
wyn[l1]=!wyn[l1];
}
}
for(int i=1; i<=n; i++){
cout<<wyn[i]<<" ";
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include<bits/stdc++.h> using namespace std; #define F first #define S second unsigned long long n; int m; int main() { cin>>n>>m; vector<pair<int,int>> rozk(m); for (int i=0; i<m; i++){ cin>>rozk[i].F>>rozk[i].S; } unsigned long long bound=1<<n; vector<bool>wyn(n+1,0); for (unsigned long long i=1; i<bound; i++){ long long l1=__builtin_popcountll(i); vector<bool> szereg(n+1,0); for (unsigned long long j=0;j<n;j++){ if((i&(1<<j))!=0) szereg[j+1]=1; } for(auto edg : rozk){ if(szereg[edg.F]&&!szereg[edg.S]){ szereg[edg.F]=0; szereg[edg.S]=1; } } bool flst=0,flend=0,flzle=0; for (long long i=1; i<=n; i++){ if(szereg[i]&&!flst) flst=1; if(flst&&!szereg[i]){ flend=1; } if(flend&&szereg[i]){ flzle=1; } } if(!flzle){ wyn[l1]=!wyn[l1]; } } for(int i=1; i<=n; i++){ cout<<wyn[i]<<" "; } } |
English