#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair P; int n, m; ll k; ll v[100010]; int p[100010]; using mint=modint1000000007; vector

g[100010]; int main() { cin>>n>>m>>k; for(int i=0; i>x>>y>>z; x--; y--; g[x].push_back({y, z}); g[y].push_back({x, z}); } mint c1=1, c2=1; bool dame=0; vector w; ll val=-1; auto dfs=[&](auto dfs, int x)->void{ w.push_back(x); for(auto q:g[x]){ int y=q.first; if(p[y]==0){ p[y]=-p[x]; v[y]=q.second-v[x]; dfs(dfs, y); }else if(p[y]!=p[x]){ if(v[y]!=q.second-v[x]){ dame=1; } }else{ ll v1=(q.second-v[x]-v[y])*p[x]; if(v1%2!=0 || v1<=0 || (val!=-1 && val!=v1/2)){ dame=1; } val=v1/2; } } }; for(int i=0; ik){ c1=0, c2=0; } } } } if(dame) cout<<0<