#include using namespace std; //#include //using namespace atcoder; using ll=long long; using Graph=vector>>; #define MAX 200003 #define INF 1000000000000000000 #define MOD 1000000007 bool dfs(Graph &G,int v,int p,vector &a,vector &color,ll &x,ll &min0,ll &max0,ll &min1,ll &max1){ if(color[v]==0){ min0=min(min0,a[v]); max0=max(max0,a[v]); }else{ min1=min(min1,a[v]); max1=max(max1,a[v]); } for(auto e:G[v]){ int nv=e.first; int sum=e.second; if(nv==p){ continue; } if(a[nv]==INF){ a[nv]=sum-a[v]; color[nv]=1-color[v]; if(dfs(G,nv,v,a,color,x,min0,max0,min1,max1)==false){ return false; } }else{ if(color[v]!=color[nv]){ if(a[v]+a[nv]!=sum){ return false; } }else{ if(x!=INF){ if(color[v]==0){ if(a[v]+a[nv]+2*x!=sum){ return false; } }else{ if(a[v]+a[nv]-2*x!=sum){ return false; } } }else{ if((sum-a[v]-a[nv])%2==1){ return false; } if(color[v]==0){ x=(sum-a[v]-a[nv])/2; }else{ x=(a[v]+a[nv]-sum)/2; } } } } } return true; } int main(){ int N,M; ll K; cin>>N>>M>>K; Graph G(N); for(int i=0;i>x>>y>>z; x--;y--; G[x].push_back(make_pair(y,z)); G[y].push_back(make_pair(x,z)); } vector a(N,INF); vector color(N,-1); bool flag=false; vector> v; for(int i=0;iK||max1-x>K){ cout<<0<K){ cout<<0<K){ cout<<0<0){ ans1++; }else{ p=min1-1; } if(min0+q>0){ ans1++; }else{ q=-min0+1; } ans2=max(0,p-q+1); ans1=min(ans1,ans2); v.push_back(make_pair(ans1,ans2)); } } } if(flag==true){ ll ans=1; for(int i=0;i