#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N,M; vector> E[202020]; vector RE[202020]; int reach[202020]; class SCC { public: static const int MV = 2025000; vector > SC; int NV,GR[MV]; private: vector E[MV], RE[MV], NUM; int vis[MV]; public: void init(int NV) { this->NV=NV; for(int i=0;i=0;i--) if(!vis[NUM[i]]){ SC[c].clear(); revdfs(NUM[i],c); sort(SC[c].begin(),SC[c].end()); c++; } SC.resize(c); } }; SCC scc; ll num[202020]; ll sum[202020]; int in[202020]; const ll mo=1000000007; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>M; scc.init(N+1); FOR(i,M) { cin>>x>>y>>j>>l; E[x].push_back({y,j,l}); RE[y].push_back(x); scc.add_edge(x,y); } queue Q; reach[N]=1; Q.push(N); while(Q.size()) { x=Q.front(); Q.pop(); FORR(e,RE[x]) if(reach[e]==0) { reach[e]=1; Q.push(e); } } scc.scc(); FOR(i,N) if(reach[i]&&scc.SC[scc.GR[i]].size()>1) { cout<<"INF"<