제출 #826023

#제출 시각아이디문제언어결과실행 시간메모리
826023becaido수천개의 섬 (IOI22_islands)C++17
0 / 100
1089 ms9868 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "islands.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const int SIZE = 2e5 + 5; int n, m; bool vs[SIZE]; vector<int> ans; vector<pair<int, int>> adj[SIZE]; int deg[SIZE]; queue<int> q; int reach() { int cnt = 0; q.push(0); vs[0] = 1; while (q.size()) { int pos = q.front(); q.pop(); cnt++; for (auto [np, id] : adj[pos]) if (!vs[np]) { vs[np] = 1; q.push(np); } } fill(vs, vs + n, 0); return cnt; } variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { n = N, m = M; for (int i = 0; i < m; i += 2) adj[U[i]].pb(V[i], i); int cnt = 0, k = reach(); FOR (i, 0, n - 1) for (auto [j, id] : adj[i]) deg[j]++; if (!deg[0]) q.push(0); while (q.size()) { int pos = q.front(); q.pop(); cnt++; for (auto [np, id] : adj[pos]) if (--deg[np] == 0) q.push(np); } if (cnt == k) return false; vector<pair<int, int>> all; auto dfs = [&](auto dfs, int pos)->bool { vs[pos] = 1; for (auto [np, id] : adj[pos]) { all.pb(pos, id); if (!vs[np]) { if (dfs(dfs, np)) return 1; all.pop_back(); continue; } int l, r = all.size() - 1; FOR (j, 0, r) if (all[j].F == np) { l = j; break; } FOR (j, 0, l - 1) ans.pb(all[j].S); FOR (j, l, r) ans.pb(all[j].S); FOR (j, l, r) ans.pb(all[j].S ^ 1); for (int j = r; j >= l; j--) ans.pb(all[j].S); for (int j = r; j >= l; j--) ans.pb(all[j].S ^ 1); for (int j = l - 1; j >= 0; j--) ans.pb(all[j].S); return 1; } vs[pos] = 0; return 0; }; if (dfs(dfs, 0) == 0) return false; return ans; } /* in1 4 5 0 1 1 2 2 3 0 3 3 1 out1 1 10 0 1 2 4 0 3 2 1 4 3 in2 2 3 0 1 1 0 1 0 out2 0 0 */ #ifdef WAIMAI int main() { int N, M; assert(2 == scanf("%d %d", &N, &M)); vector<int> U(M), V(M); for (int i = 0; i < M; ++i) { assert(2 == scanf("%d %d", &U[i], &V[i])); } variant<bool, vector<int>> result = find_journey(N, M, U, V); if (result.index() == 0) { printf("0\n"); if (get<bool>(result)) { printf("1\n"); } else { printf("0\n"); } } else { printf("1\n"); vector<int> &canoes = get<vector<int>>(result); printf("%d\n", static_cast<int>(canoes.size())); for (int i = 0; i < static_cast<int>(canoes.size()); ++i) { if (i > 0) { printf(" "); } printf("%d", canoes[i]); } printf("\n"); } return 0; } #endif

컴파일 시 표준 에러 (stderr) 메시지

islands.cpp: In lambda function:
islands.cpp:88:35: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |             for (int j = l - 1; j >= 0; j--) ans.pb(all[j].S);
      |                                 ~~^~~~
islands.cpp:87:31: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |             for (int j = r; j >= l; j--) ans.pb(all[j].S ^ 1);
      |                             ~~^~~~
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:88:22: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |             for (int j = l - 1; j >= 0; j--) ans.pb(all[j].S);
      |                      ^
#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...