제출 #1010863

#제출 시각아이디문제언어결과실행 시간메모리
1010863GrindMachine수천개의 섬 (IOI22_islands)C++17
55 / 100
36 ms10836 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif /* */ const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; #include "islands.h" vector<pii> adj[N]; vector<bool> vis(N), recstack(N); vector<pii> par(N,{-1,-1}); bool cyc = false; vector<int> ans; void dfs1(int u){ vis[u] = 1; recstack[u] = 1; for(auto [v,id] : adj[u]){ if(vis[v]){ if(recstack[v]){ if(!cyc){ cyc = true; int curr = u; vector<int> cyc_edges; while(curr != v){ cyc_edges.pb(par[curr].ss); curr = par[curr].ff; } reverse(all(cyc_edges)); cyc_edges.pb(id); vector<int> par_edges; curr = v; while(curr){ par_edges.pb(par[curr].ss); curr = par[curr].ff; } ans = par_edges; reverse(all(ans)); trav(x,cyc_edges) ans.pb(x); ans.pb(cyc_edges[0]^1); ans.pb(cyc_edges[0]); rev(i,sz(cyc_edges)-1,1){ ans.pb(cyc_edges[i]); } ans.pb(cyc_edges[0]^1); trav(x,par_edges) ans.pb(x); } } } else{ par[v] = {u,id}; dfs1(v); } } recstack[u] = 0; } bool line = true; vector<bool> good(N); void dfs2(int u, int p){ vis[u] = 1; int d = sz(adj[u])-(p != -1); if(d >= 2){ good[u] = 1; line = false; } for(auto [v,id] : adj[u]){ if(v == p or vis[v]) conts; par[v] = {u,id}; dfs2(v,u); } } std::variant<bool, std::vector<int>> find_journey( int n, int m, std::vector<int> U, std::vector<int> V) { rep(i,m){ int u = U[i], v = V[i]; adj[u].pb({v,i}); } if(n == 2){ if(!(sz(adj[0]) >= 2 and sz(adj[1]) >= 1)){ return false; } int x = adj[0][0].ss, y = adj[0][1].ss, z = adj[1][0].ss; vector<int> ans = {x,z,y,x,z,y}; return ans; } bool subtask4 = true, subtask3 = true; rep(i,m){ if(!(m&1)){ if(U[i] == U[i^1] and V[i] == V[i^1]){ } else{ subtask4 = false; } swap(U[i],V[i]); if(U[i] == U[i^1] and V[i] == V[i^1]){ } else{ subtask3 = false; } swap(U[i],V[i]); } } if(subtask4){ dfs1(0); if(cyc) return ans; else return false; } if(subtask3){ dfs2(0,-1); if(line){ return false; } rep(i,n){ if(!good[i]) conts; bool ok = true; int u = i; vector<int> edges; while(true){ auto [p,pid] = par[u]; if(p == -1) break; edges.pb(pid); u = p; if(good[u]){ ok = false; break; } } if(!ok) conts; vector<int> seq; vector<int> v1; for(auto [v,id] : adj[i]){ if(count(all(edges),id^1)) conts; v1.pb(id); } assert(sz(v1) >= 2); while(sz(v1) > 2) v1.pop_back(); int x = v1[0], y = v1[1]; seq = {x,x^1,y,y^1,x^1,x,y^1,y}; ans = edges; reverse(all(ans)); trav(x,seq) ans.pb(x); trav(x,edges) ans.pb(x); return ans; } assert(0); } vector<pii> edges = { {0,1}, {1,0}, {0,2}, {2,0}, {1,0}, {0,1}, {2,0}, {0,2} }; vector<int> ans; for(auto [u,v] : edges){ for(auto [vv,idd] : adj[u]){ if(vv == v){ ans.pb(idd); break; } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...