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 48 49 50 51 52 53 54 55 56 57 58
| #include<bits/stdc++.h> #define Tp template<typename Ty> #define Ts template<typename Ty,typename... Ar> #define W while #define I inline #define RI register int #define LL long long #define Cn const #define CI Cn int& #define gc getchar #define D isdigit(c=gc()) #define pc(c) putchar((c)) using namespace std; namespace Debug{ Tp I void _debug(Cn char* f,Ty t){cerr<<f<<'='<<t<<endl;} Ts I void _debug(Cn char* f,Ty x,Ar... y){W(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);} Tp ostream& operator<<(ostream& os,Cn vector<Ty>& V){os<<"[";for(Cn auto& vv:V) os<<vv<<",";os<<"]";return os;} #define gdb(...) _debug(#__VA_ARGS__,__VA_ARGS__) }using namespace Debug; namespace FastIO{ Tp I void read(Ty& x){char c;int f=1;x=0;W(!D) f=c^'-'?1:-1;W(x=(x<<3)+(x<<1)+(c&15),D);x*=f;} Ts I void read(Ty& x,Ar&... y){read(x),read(y...);} Tp I void write(Ty x){x<0&&(pc('-'),x=-x,0),x<10?(pc(x+'0'),0):(write(x/10),pc(x%10+'0'),0);} Tp I void writeln(Cn Ty& x){write(x),pc('\n');} }using namespace FastIO; Cn int N=5e4+10,M=N*10; int n,m,cnt,dfn[M],stk[M],low[M],col[M],cc,top,nc; struct edge{int u,v,c,t;}a[N]; #define vi vector<int> #define pb push_back vi v[N],A,e[M]; I void LK(CI o){ RI F=-1,T;for(auto i:A){ RI f=++cnt,t=++cnt;e[o?i:i+m].pb(f),e[t].pb(o?i+m:i); ~F&&(e[F].pb(f),e[t].pb(T),e[F].pb(o?i+m:i),e[o?i:i+m].pb(T),0);F=f,T=t; } } I void Tarjan(CI x){ stk[++top]=x,dfn[x]=low[x]=++nc;for(auto i:e[x]) if(!dfn[i]) Tarjan(i),low[x]=min(low[x],low[i]);else if(!col[i]) low[x]=min(low[x],dfn[i]); if(dfn[x]==low[x]){col[x]=++cc;W(stk[top]^x) col[stk[top--]]=cc;top--;} } I void Cl(CI x){RI i;for(i=1;i<=m;i++) a[i].t>x&&(assert(e[i].back()==i+m),e[i].pop_back(),0);} I bool chk(CI x){ RI i;for(i=1;i<=m;i++) a[i].t>x&&(e[i].pb(i+m),0); for(top=nc=cc=0,i=1;i<=cnt;i++) dfn[i]=col[i]=0; for(i=1;i<=cnt;i++) !dfn[i]&&(Tarjan(i),0); for(i=1;i<=m;i++) if(col[i]==col[i+m]) return Cl(x),0; return Cl(x),1; } int main(){ RI i,l=0,r=0,mid;for(read(n,m),cnt=m<<1,i=1;i<=m;i++) read(a[i].u,a[i].v,a[i].c,a[i].t),r=max(r,a[i].t),v[a[i].u].pb(i),v[a[i].v].pb(i);for(i=1;i<=n;i++){ sort(v[i].begin(),v[i].end(),[&](CI x,CI y){return a[x].c<a[y].c;}),A.clear(),A=v[i],LK(1); for(RI tl=0,tr=0;tl<v[i].size();LK(0),tl=++tr){A.clear(),A.pb(v[i][tl]);W(tr+1<v[i].size()&&a[v[i][tr+1]].c==a[v[i][tr]].c) A.pb(v[i][++tr]);} }if(!chk(r)) return puts("No"),0; puts("Yes");W(l<r) chk(mid=l+r>>1)?r=mid:l=mid+1; for(write(l),pc(' '),chk(l),A.clear(),i=1;i<=m;i++) col[i]<col[i+m]&&(A.pb(i),0); writeln(A.size());for(auto i:A) write(i),pc(' ');return 0; }
|