#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int c,n,m,vis[3000];
vector<int>vec[MAX];
void dfs(int x)
{
vis[x]=1;
c++;
int i;
for(i=0;i<vec[x].size();i++)
{
if(vis[vec[x][i]]==0)
dfs(vec[x][i]);
}
}
int main()
{
int r,k,i,x=0,y=0,j,t,l,flag,x1=0,y1=0,z;
ll ans=0;
string p;
while(1)
{
cin>>n>>m;
if(n==0 && m==0)
break;
for(i=1; i<=m; i++)
{
cin>>x>>y>>z;
if(z==1)
vec[x].push_back(y);
else
{
vec[x].push_back(y);
vec[y].push_back(x);
}
}
flag=0;
for(i=1; i<=n; i++)
{
memset(vis,0,sizeof(vis));
c=0;
dfs(i);
if(c!=n)
{
flag=1;
break;
}
}
for(i=1; i<=n+5; i++)
vec[i].clear();
if(flag)
cout<<0<<endl;
else
cout<<1<<endl;
}
return 0;
}
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int c,n,m,vis[3000];
vector<int>vec[MAX];
void dfs(int x)
{
vis[x]=1;
c++;
int i;
for(i=0;i<vec[x].size();i++)
{
if(vis[vec[x][i]]==0)
dfs(vec[x][i]);
}
}
int main()
{
int r,k,i,x=0,y=0,j,t,l,flag,x1=0,y1=0,z;
ll ans=0;
string p;
while(1)
{
cin>>n>>m;
if(n==0 && m==0)
break;
for(i=1; i<=m; i++)
{
cin>>x>>y>>z;
if(z==1)
vec[x].push_back(y);
else
{
vec[x].push_back(y);
vec[y].push_back(x);
}
}
flag=0;
for(i=1; i<=n; i++)
{
memset(vis,0,sizeof(vis));
c=0;
dfs(i);
if(c!=n)
{
flag=1;
break;
}
}
for(i=1; i<=n+5; i++)
vec[i].clear();
if(flag)
cout<<0<<endl;
else
cout<<1<<endl;
}
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন