제출 #1135148

#제출 시각아이디문제언어결과실행 시간메모리
1135148Lemser수천개의 섬 (IOI22_islands)C++20
8.40 / 100
63 ms12204 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using lld = long double; using ii = pair<int,int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; using vpll = vector<pll>; using vlld = vector<lld>; // #define endl '\n' #define all(x) x.begin(),x.end() #define lsb(x) x&(-x) #define gcd(a,b) __gcd(a,b) #define sz(x) (int)x.size() #define mp make_pair #define pb push_back #define fi first #define se second #define fls cout.flush() #define fore(i,l,r) for(auto i=l;i<r;i++) #define fo(i,n) fore(i,0,n) #define forex(i,r,l) for(auto i=r; i>=l;i--) #define ffo(i,n) forex(i,n-1,0) bool cmin(ll &a, ll b) { if(b<a){a=b;return 1;}return 0; } bool cmax(ll &a, ll b) { if(b>a){a=b;return 1;}return 0; } void valid(ll in) { cout<<((in)?"Yes\n":"No\n"); } ll lcm(ll a, ll b) { return (a/gcd(a,b))*b; } ll gauss(ll n) { return (n*(n+1))/2; } const ll INF = 1e18; const int N = 1005; ll vis[N], dp[N], ans; stack<ll> stk, rs; vector<vector<array<ll, 2>>> gr; vector<int> r; void dfs (ll u, ll pr) { if (sz(r)) return; stk.push(u); rs.push(pr); vis[u] = 1; for (auto [v, i]: gr[u]) { if (sz(r)) return; if (vis[v]) { // cout << "OKKK\n"; // exit(0); ans = 1; vll clrs; clrs.pb(i); while (sz(stk) && stk.top() != v) { clrs.pb(rs.top()); stk.pop(); rs.pop(); } reverse(all(clrs)); ll ot = (clrs[0]&1 ? clrs[0]-1 : clrs[0]+1); vll B; while (rs.top() != -1) { B.pb(rs.top()); rs.pop(); } reverse(all(B)); for (ll i: B) r.pb(i); fo (x, sz(clrs)) { for (ll i: clrs) r.pb(i); r.pb(ot); } // cout << "bullshit " << clrs[0] << '\n'; // r.pb(clrs[0]); reverse(all(B)); for (ll i: B) r.pb(i); return; } else { if (dp[v]) continue; if (sz(r)) return; dfs(v, i); } } if (sz(r)) return; dp[u] = 1; vis[u] = 0; if (stk.top() == u) stk.pop(); if (rs.top() == pr) rs.pop(); } variant<bool, vector<int>> find_journey( int n, int m, vector<int> u, vector<int> v) { // if (n == 2) { // vll ok[2]; // fo (i, m) ok[u[i]].pb(i); // if (sz(ok[0]) < 2 || sz(ok[1]) < 1) return false; // vector<int> r; // r.pb(ok[0][0]); // r.pb(ok[1][0]); // r.pb(ok[0][1]); // r.pb(ok[0][0]); // r.pb(ok[1][0]); // r.pb(ok[0][1]); // return r; // } gr = vector<vector<array<ll, 2>>>(n); for (ll i = 0; i < m ; i += 2) { gr[u[i]].pb({v[i], i}); } ans = 0; dfs(0, -1); if (ans == 0) return false; return r; }
#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...