제출 #1297881

#제출 시각아이디문제언어결과실행 시간메모리
1297881Dreamy_lovesperFirefighting (NOI20_firefighting)C++20
3 / 100
135 ms32332 KiB
// I also thought that there was a small chance that she likes me back. #include <bits/stdc++.h> using namespace std; // Do you think you'll ever remember me someday, or will I just fade away from your memory? #define LIFESUCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define str string #define mll map<ll, ll> #define vll vector<ll> #define pll pair<ll, ll> #define fi first #define se second #define all(c) c.begin(), c.end() #define pb push_back #define sz(s) s.size() #define debug cout << "I Love You\n"; #define fu(i, a, b) for (ll i = a; i <= b; i++) #define fd(i, b, a) for (ll i = b; i >= a; i--) #define Bitc(msk, j) ((msk >> j) & 1) #define _log(x) 31 - __builtin_clz(x) #define LoveTime chrono::steady_clock::now().time_since_epoch().count() const ll Mod = 998244353; const ll inf = (1ll << 30); const ll lnf = (1ll << 60); // When time passes and things change... will you still remember someone like me? int64_t add(ll& a, ll b) { a += b; if (a >= Mod) a %= Mod; while (a < 0) a += Mod; return a; } int64_t mul(ll a, ll b) { a = 1ll * a * b % Mod; return a; } template <class X, class Y> bool minimize(X& x, Y y) { X eps = 1e-9; if (x > y + eps) { x = y; return 1; } return 0; } template <class X, class Y> bool maximize(X& x, Y y) { X eps = 1e-9; if (x + eps < y) { x = y; return 1; } return 0; } // I wonder… will I just become a distant memory to you one day? #define mxn 300'007 ll n, k, g[mxn]; vector<pll> graph[mxn]; struct Edge { ll u, v, w; } edge[mxn]; namespace Love1 { bool check() { fu(i, 2, n) if(edge[i].w <= k) return 0; return 1; } void DreamyLove () { cout << n << '\n'; fu(i, 1, n) cout << i << ' '; // } } namespace Love23 { bool check() { return (n <= 17); } ll vis[27]; void DreamyLove () { ll sad = lnf; ll trace; fu(msk, 1, (1 << n) - 1) { ll cnt = __builtin_popcount(msk); if(cnt >= sad) continue; queue<pll> Q; ll cr = cnt; fu(i, 1, n) vis[i] = 0; fu(i, 0, n - 1) if(Bitc(msk, i)) Q.push({i + 1, 0}), vis[i] = 1; while(!Q.empty()) { auto[u, wei] = Q.front(); Q.pop(); for(auto&[v, w]: graph[u]) { if(vis[v]) continue; if(wei + w > k) continue; cr++; vis[v] = 1; Q.push({v, wei + w}); } } if(cr == n) sad = cnt, trace = msk; } cout << sad << '\n'; fu(i, 0, n - 1) if(Bitc(trace, i)) cout << i + 1 << ' '; // } } // The world is still beautiful, only it’s a pity that you are no longer among the living. void lovesper(const ll& TestCase) { cin >> n >> k; fu(i, 2, n) { ll u, v, w;cin >> u >> v >> w; edge[i] = {u, v, w}; graph[u].pb({v, w}); graph[v].pb({u, w}); } if(Love1::check()) { Love1::DreamyLove(); return; } if(Love23::check()) { Love23::DreamyLove(); return; } } // In the future, each of us will have our own path.. // ...But no matter where we go, we will always be a beautiful part of each other’s memories. signed main() { LIFESUCK #define name "lovesper" // freopen(name".inp", "r", stdin); // freopen(name".out", "w", stdout); // carr.close(); ll Test = 1; // cin >> Test; fu(i, 1, Test) { lovesper(i); if (i < Test) cout << '\n'; } return 0; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...