update
This commit is contained in:
		
							parent
							
								
									5e77358d92
								
							
						
					
					
						commit
						1efcad447b
					
				
							
								
								
									
										105
									
								
								src/11/25/U86017.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								src/11/25/U86017.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,105 @@ | |||||||
|  | #include <algorithm> | ||||||
|  | #include <cstdint> | ||||||
|  | #include <functional> | ||||||
|  | #include <ios> | ||||||
|  | #include <iostream> | ||||||
|  | #include <map> | ||||||
|  | #include <ostream> | ||||||
|  | #include <utility> | ||||||
|  | 
 | ||||||
|  | using namespace std; | ||||||
|  | using ll = int64_t; | ||||||
|  | 
 | ||||||
|  | template<class T,class P> | ||||||
|  | ostream&operator<<(ostream&os,map<T,P>const&m){ | ||||||
|  |     os<<"map { "; | ||||||
|  |     for(auto [k,v]:m){ | ||||||
|  |         os<<"{ "<<k<<", "<<v<<" }, "; | ||||||
|  |     } | ||||||
|  |     os<<"}"; | ||||||
|  |     return os; | ||||||
|  | } | ||||||
|  | template<class T,class P> | ||||||
|  | ostream&operator<<(ostream&os,pair<T,P>const&m){ | ||||||
|  |     os<<"pair { "<<m.first<<", "<<m.second<<" }"; | ||||||
|  |     return os; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ll const maxn{ll(1e5+5)}; | ||||||
|  | ll t,n,m,inf{ll(1)<<60}; | ||||||
|  | ll q[maxn],qs{}; | ||||||
|  | pair<ll, ll>e[maxn]; | ||||||
|  | 
 | ||||||
|  | struct DSU{ | ||||||
|  |     ll f[maxn]; | ||||||
|  |     DSU(){for(ll i{1};i<=n;i++){f[i]=i;}} | ||||||
|  |     ll find(ll const&n){if(f[n]==n)return n; return f[n]=find(f[n]);} | ||||||
|  |     bool merge(ll const&a,ll const&b){if(find(a)==find(b))return false;f[find(a)]=find(b);return true;} | ||||||
|  |     friend ostream&operator<<(ostream&os,DSU const& d){ | ||||||
|  |         os<<"DSU { "; | ||||||
|  |         for(ll i{1};i<=n;i++)os<<d.f[i]<<", "; | ||||||
|  |         os<<"}"; | ||||||
|  |         return os; | ||||||
|  |     } | ||||||
|  | }; | ||||||
|  | char dmem[sizeof(DSU)+1024]; | ||||||
|  | DSU &dsu = *(DSU*)dmem; | ||||||
|  | ll un[maxn]; | ||||||
|  | 
 | ||||||
|  | int main(){ | ||||||
|  |     ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); | ||||||
|  | 
 | ||||||
|  |     cin>>t; | ||||||
|  |     while(t--){ | ||||||
|  |         cin>>n>>m; | ||||||
|  |         // cout<<n<<" "<<m<<'\n';
 | ||||||
|  |         for(ll i{1};i<=m;i++){ | ||||||
|  |             ll u,v; | ||||||
|  |             cin>>u>>v; | ||||||
|  |             if(u>v)swap(u,v); | ||||||
|  |             // cout<<"uv "<<u<<' '<<v<<'\n';
 | ||||||
|  |             e[i].first=u,e[i].second=v; | ||||||
|  |         } | ||||||
|  |         sort(e+1,e+1+m,greater()); | ||||||
|  |         new(dmem) DSU(); | ||||||
|  |         // cout<<dsu<<'\n';
 | ||||||
|  |         ll uns{}; | ||||||
|  |         for(ll i{1};i<=m;i++){ | ||||||
|  |             // cout<<e[i]<<'\n';
 | ||||||
|  |             if(!dsu.merge(e[i].first, e[i].second)){ | ||||||
|  |                 un[++uns]=i; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         // cout<<dsu<<'\n';
 | ||||||
|  |         map<ll, ll> mm; | ||||||
|  |         for(ll i{1};i<=n;i++){ | ||||||
|  |             mm[dsu.find(i)] = min(mm[dsu.find(i)]==0?inf:mm[dsu.find(i)],i); | ||||||
|  |         } | ||||||
|  |         // cout<<mm<<' '<<uns<<' '<<un[uns]<<' '<<e[un[uns]]<<'\n';
 | ||||||
|  |         // cout<<mm.size()<<' '<<uns<<'\n';
 | ||||||
|  |         if((ll)mm.size()-1>uns&&mm.size()!=1){ | ||||||
|  |             cout<<"-1"<<'\n'; | ||||||
|  |             continue; | ||||||
|  |         } | ||||||
|  |         if(mm.size()==1){ | ||||||
|  |             cout<<"0\n"; | ||||||
|  |             continue; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         qs=0; | ||||||
|  |         for(auto const[k,v]:mm){ | ||||||
|  |             q[++qs]=v; | ||||||
|  |         } | ||||||
|  |         sort(q+1,q+1+qs); | ||||||
|  |         // cout<<mm<<'\n';
 | ||||||
|  |         // for(ll i{1};i<=qs;i++)cout<<q[i]<<" ,";
 | ||||||
|  |         // cout<<'\n';
 | ||||||
|  |         // cout<<mm<<'\n';
 | ||||||
|  |         cout<<mm.size()-1<<'\n'; | ||||||
|  |         for(ll i{2};i<=qs;i++){ | ||||||
|  |             cout<<e[un[uns]].first<<" "<<e[un[uns-1]].second<<" "<<q[1]<<" "<<q[i]<<'\n'; | ||||||
|  |             --uns; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										3
									
								
								src/11/25/rebuild/rebuild1.ans
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/11/25/rebuild/rebuild1.ans
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | 1 | ||||||
|  | 2 5 1 2 | ||||||
|  | 0 | ||||||
							
								
								
									
										9
									
								
								src/11/25/rebuild/rebuild1.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/11/25/rebuild/rebuild1.in
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | 2 | ||||||
|  | 5 5 | ||||||
|  | 1 3 | ||||||
|  | 3 4 | ||||||
|  | 5 2 | ||||||
|  | 5 2 | ||||||
|  | 2 5 | ||||||
|  | 2 1 | ||||||
|  | 1 2 | ||||||
							
								
								
									
										5
									
								
								src/11/25/rebuild/rebuild2.ans
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/11/25/rebuild/rebuild2.ans
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | |||||||
|  | 0 | ||||||
|  | -1 | ||||||
|  | 2 | ||||||
|  | 1 2 1 5 | ||||||
|  | 1 3 1 6 | ||||||
							
								
								
									
										19
									
								
								src/11/25/rebuild/rebuild2.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/11/25/rebuild/rebuild2.in
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | |||||||
|  | 3 | ||||||
|  | 5 4 | ||||||
|  | 1 3 | ||||||
|  | 3 4 | ||||||
|  | 5 2 | ||||||
|  | 1 2 | ||||||
|  | 5 3 | ||||||
|  | 1 3 | ||||||
|  | 3 4 | ||||||
|  | 5 2 | ||||||
|  | 7 8 | ||||||
|  | 1 2 | ||||||
|  | 2 3 | ||||||
|  | 3 1 | ||||||
|  | 1 4 | ||||||
|  | 2 4 | ||||||
|  | 4 3 | ||||||
|  | 6 7 | ||||||
|  | 7 6 | ||||||
							
								
								
									
										16
									
								
								src/11/25/rebuild/rebuild3.ans
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/11/25/rebuild/rebuild3.ans
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | |||||||
|  | 2 | ||||||
|  | 1 2 1 7 | ||||||
|  | 1 5 1 8 | ||||||
|  | 1 | ||||||
|  | 3 7 1 2 | ||||||
|  | 4 | ||||||
|  | 1 5 1 2 | ||||||
|  | 1 6 1 3 | ||||||
|  | 1 6 1 4 | ||||||
|  | 1 7 1 8 | ||||||
|  | 3 | ||||||
|  | 1 4 1 6 | ||||||
|  | 1 9 1 7 | ||||||
|  | 1 9 1 10 | ||||||
|  | 1 | ||||||
|  | 3 9 1 10 | ||||||
							
								
								
									
										56
									
								
								src/11/25/rebuild/rebuild3.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								src/11/25/rebuild/rebuild3.in
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,56 @@ | |||||||
|  | 5 | ||||||
|  | 10 10 | ||||||
|  | 1 10 | ||||||
|  | 2 1 | ||||||
|  | 2 5 | ||||||
|  | 1 6 | ||||||
|  | 9 1 | ||||||
|  | 5 9 | ||||||
|  | 1 6 | ||||||
|  | 1 4 | ||||||
|  | 1 5 | ||||||
|  | 1 3 | ||||||
|  | 10 10 | ||||||
|  | 3 9 | ||||||
|  | 3 7 | ||||||
|  | 5 10 | ||||||
|  | 8 6 | ||||||
|  | 6 1 | ||||||
|  | 4 10 | ||||||
|  | 7 9 | ||||||
|  | 9 1 | ||||||
|  | 3 5 | ||||||
|  | 3 9 | ||||||
|  | 10 10 | ||||||
|  | 1 7 | ||||||
|  | 1 6 | ||||||
|  | 3 10 | ||||||
|  | 9 1 | ||||||
|  | 1 5 | ||||||
|  | 1 5 | ||||||
|  | 6 7 | ||||||
|  | 1 6 | ||||||
|  | 1 7 | ||||||
|  | 9 1 | ||||||
|  | 10 10 | ||||||
|  | 9 2 | ||||||
|  | 3 5 | ||||||
|  | 5 8 | ||||||
|  | 1 4 | ||||||
|  | 9 1 | ||||||
|  | 9 1 | ||||||
|  | 1 9 | ||||||
|  | 1 4 | ||||||
|  | 9 1 | ||||||
|  | 1 5 | ||||||
|  | 10 10 | ||||||
|  | 8 1 | ||||||
|  | 3 1 | ||||||
|  | 9 3 | ||||||
|  | 2 4 | ||||||
|  | 7 3 | ||||||
|  | 3 9 | ||||||
|  | 9 3 | ||||||
|  | 2 3 | ||||||
|  | 5 3 | ||||||
|  | 6 5 | ||||||
							
								
								
									
										60710
									
								
								src/11/25/rebuild/rebuild4.ans
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60710
									
								
								src/11/25/rebuild/rebuild4.ans
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										552692
									
								
								src/11/25/rebuild/rebuild4.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										552692
									
								
								src/11/25/rebuild/rebuild4.in
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user