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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
| #include<bits/stdc++.h> #define gc getchar #define pc putchar #define F(i,x,y) for(int i=x;i<=y;++i) #define R(i,x,y) for(int i=x;i>=y;--i) inline int read(){ int x=0;char ch=gc();bool p=1; while (!isdigit(ch)) ch=='-'?p=0:0,ch=gc(); while ( isdigit(ch)) x=(x<<1)+(x<<3)+(ch^'0'),ch=gc(); return p?x:-x; } const int N=1e5+5,INF=1e9+7; struct Edge{ int pos,val; }; std::vector<Edge> G[N]; int n,m,dfn[N],dep[N],top[N],fa[N],son[N],sz[N],val[N],tot,vvv[N]; void Dfs0(int cur){ sz[cur]=1; dep[cur]=dep[fa[cur]]+1; F(i,0,(int)G[cur].size()-1){ int to=G[cur][i].pos,v=G[cur][i].val; if (to==fa[cur]) continue; fa[to]=cur; vvv[to]=v; Dfs0(to); sz[cur]+=sz[to]; if (sz[to]>sz[son[cur]]) son[cur]=to; } } void Dfs1(int cur){ dfn[cur]=++tot; val[dfn[cur]]=vvv[cur]; if (!top[cur]) top[cur]=cur; if (son[cur]) top[son[cur]]=top[cur],Dfs1(son[cur]); F(i,0,(int)G[cur].size()-1){ int to=G[cur][i].pos; if (to==fa[cur]||to==son[cur]) continue; Dfs1(to); } } #define min std::min #define max std::max #define mid ((l+r)>>1) int lz[N<<2],minn[N<<2],maxn[N<<2]; inline void pushup(int k){ minn[k]=min(minn[k<<1],minn[k<<1|1]); } inline void putmin(int k,int v){ minn[k]=min(minn[k],v),lz[k]=min(lz[k],v); } inline void pushdown(int k){ if (lz[k]!=INF) putmin(k<<1,lz[k]),putmin(k<<1|1,lz[k]),lz[k]=INF; } void Build(int k,int l,int r){ lz[k]=INF; if (l==r) return minn[k]=INF,maxn[k]=val[l],void(); Build(k<<1,l,mid),Build(k<<1|1,mid+1,r); pushup(k);maxn[k]=max(maxn[k<<1],maxn[k<<1|1]); } void Modify(int k,int l,int r,int le,int ri,int v){ if (l>=le&&r<=ri) return putmin(k,v); pushdown(k); if (mid>=le) Modify(k<<1,l,mid,le,ri,v); if (mid< ri) Modify(k<<1|1,mid+1,r,le,ri,v); pushup(k); } int Querymax(int k,int l,int r,int le,int ri){ if (l>=le&&r<=ri) return maxn[k]; int res=0;pushdown(k); if (mid>=le) res=max(res,Querymax(k<<1,l,mid,le,ri)); if (mid< ri) res=max(res,Querymax(k<<1|1,mid+1,r,le,ri)); return res; } int Querymin(int k,int l,int r,int pos){ if (l==r) return minn[k]; pushdown(k); if (mid>=pos) return Querymin(k<<1,l,mid,pos); else return Querymin(k<<1|1,mid+1,r,pos); } inline bool Add(int x,int y,int v){ std::vector<Edge> p; while (top[x]!=top[y]){ if (dep[top[x]]<dep[top[y]]) x^=y^=x^=y; p.push_back({dfn[top[x]],dfn[x]}); x=fa[top[x]]; } if (x!=y){ if (dep[x]<dep[y]) x^=y^=x^=y; p.push_back({dfn[y]+1,dfn[x]}); } bool flag=0; F(i,0,(int)p.size()-1){ int l=p[i].pos,r=p[i].val; Modify(1,1,n,l,r,v); if (Querymax(1,1,n,l,r)==v) flag=1; } return flag; } struct eee{ int l,r,val,tag; } w[N]; inline bool operator < (eee a,eee b){ return a.val<b.val; } int f[N]; inline int find(int x){ if (x==f[x]) return x; return f[x]=find(f[x]); } int ans[N]; signed main(){ n=read(),m=read(); F(i,1,n) f[i]=i; F(i,1,m){ w[i].l=read(),w[i].r=read(),w[i].val=read(),w[i].tag=i; } std::sort(w+1,w+1+m); F(i,1,m){ int x=w[i].l,y=w[i].r,v=w[i].val; if (find(x)==find(y)) continue; f[find(x)]=find(y); G[x].push_back({y,v}); G[y].push_back({x,v}); } Dfs0(1),Dfs1(1); Build(1,1,n); F(i,1,m){ int x=w[i].l,y=w[i].r,v=w[i].val; if (fa[x]!=y&&fa[y]!=x){ ans[w[i].tag]=Add(x,y,v)?2:3; } } F(i,1,m){ int x=w[i].l,y=w[i].r; if (fa[x]==y||fa[y]==x){ if (dep[x]<dep[y]) x^=y^=x^=y; if (Querymin(1,1,n,dfn[x])==Querymax(1,1,n,dfn[x],dfn[x])) ans[w[i].tag]=2; else ans[w[i].tag]=1; } } F(i,1,m){ if (ans[i]==1) puts("any"); else if (ans[i]==2) puts("at least one"); else puts("none"); } return 0; }
|