Submission #634743

#TimeUsernameProblemLanguageResultExecution timeMemory
634743CauchicoThousands Islands (IOI22_islands)C++17
Compilation error
0 ms0 KiB
//#include <variant> #include <bits/stdc++.h> using namespace std; vector<vector<pair<int,int>>> adj; vector<vector<int>> adj_rev; vector<int> path; vector<bool> used; int loop = -1; void dfs(int v) { used[v] = true; for (auto u: adj[v]) { if (!used[u.first]) { path.push_back(u.second); dfs(u.first); } else { path.push_back(u.second); loop = u.first; return; } if (loop == -1) { path.pop_back(); } else { return; } } } vector<bool> used1; vector<int> order; void dfs1(int v) { used[v] = true; for (auto u : adj[v]) if (!used1[u.first]) dfs1(u.first); order.push_back(v); } bool dfs2(int v) { used[v] = true; for (auto u : adj_rev[v]) if (!used[u]) return true; } vector<int> find_journey( int n, int m, vector<int> u, vector<int> v) { adj.resize(n); used.resize(n); used1.resize(n); adj_rev.resize(n); for (int i=0;i<m;i+=2) { adj[u[i]].push_back({v[i],i}); adj_rev[v[i]].push_back(u[i]); } bool loop = false; dfs1(0); reverse(order.begin(), order.end()); for (auto u: order) loop |= dfs2(u); dfs(0); vector<int> route,cycle; bool inroute = true; for (int i=0;i<path.size();i++) { if (u[path[i]] == loop) { inroute = false; } if (inroute) { route.push_back(path[i]); } else { cycle.push_back(path[i]); } } int lenc = cycle.size(); vector<int> p1=route,b1=route,c1=cycle,d1=cycle,c2,d2; reverse(b1.begin(),b1.end()); reverse(d1.begin(),d1.end()); for (int i=0;i<lenc;i++) { c2[i] = c1[i]^1; } c2 = d2; reverse(d2.begin(),d2.end()); vector<int> ans; ans.insert(ans.end(),p1.begin(),p1.end()); ans.insert(ans.end(),c1.begin(),c1.end()); ans.insert(ans.end(),c2.begin(),c2.end()); ans.insert(ans.end(),d1.begin(),d1.end()); ans.insert(ans.end(),d2.begin(),d2.end()); ans.insert(ans.end(),b1.begin(),b1.end()); for (auto u: p1) cout << u << " "; cout << "\n"; for (auto u: c1) cout << u << " "; cout << "\n"; for (auto u: c2) cout << u << " "; cout << "\n"; for (auto u: d1) cout << u << " "; cout << "\n"; for (auto u: d2) cout << u << " "; cout << "\n"; for (auto u: b1) cout << u << " "; cout << "\n"; return ans; } int main() { int n,m; cin >> n >> m; vector<int> u(m),v(m); for (int i=0;i<m;i++) { int a,b; cin >> a >> b; u[i] = a; v[i] = b; } vector<int> a = find_journey(n,m,u,v); }

Compilation message (stderr)

islands.cpp: In function 'std::vector<int> find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i=0;i<path.size();i++) {
      |                  ~^~~~~~~~~~~~
islands.cpp:86:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   86 |   for (auto u: p1) cout << u << " "; cout << "\n";
      |   ^~~
islands.cpp:86:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   86 |   for (auto u: p1) cout << u << " "; cout << "\n";
      |                                      ^~~~
islands.cpp:87:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   87 |   for (auto u: c1) cout << u << " "; cout << "\n";
      |   ^~~
islands.cpp:87:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   87 |   for (auto u: c1) cout << u << " "; cout << "\n";
      |                                      ^~~~
islands.cpp:88:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   88 |   for (auto u: c2) cout << u << " "; cout << "\n";
      |   ^~~
islands.cpp:88:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   88 |   for (auto u: c2) cout << u << " "; cout << "\n";
      |                                      ^~~~
islands.cpp:89:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   89 |   for (auto u: d1) cout << u << " "; cout << "\n";
      |   ^~~
islands.cpp:89:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   89 |   for (auto u: d1) cout << u << " "; cout << "\n";
      |                                      ^~~~
islands.cpp:90:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   90 |   for (auto u: d2) cout << u << " "; cout << "\n";
      |   ^~~
islands.cpp:90:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   90 |   for (auto u: d2) cout << u << " "; cout << "\n";
      |                                      ^~~~
islands.cpp:91:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   91 |   for (auto u: b1) cout << u << " "; cout << "\n";
      |   ^~~
islands.cpp:91:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   91 |   for (auto u: b1) cout << u << " "; cout << "\n";
      |                                      ^~~~
islands.cpp: In function 'bool dfs2(int)':
islands.cpp:45:1: warning: control reaches end of non-void function [-Wreturn-type]
   45 | }
      | ^
/usr/bin/ld: /tmp/cciZ7Ryr.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc5LUS3u.o:islands.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status