Submission #623836

#TimeUsernameProblemLanguageResultExecution timeMemory
623836AlmaPipes (CEOI15_pipes)C++17
10 / 100
5068 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second using ll = long long; using ii = pair<int,int>; const int INF = 1e9; const ll LLINF = 1e18; using vi = vector<int>; using vvi = vector<vi>; void setIO (string fileName) { ios::sync_with_stdio(false); cin.tie(NULL); if (fileName != "std") { freopen((fileName + ".in").c_str(), "r", stdin); freopen((fileName + ".out").c_str(), "w", stdout); } } vi st, path, par; vvi adj; int uFind(int u) { if (par[u] == u) return u; return par[u] = uFind(par[u]); } void uJoin (int u, int v) { int a = uFind(u), b = uFind(v); par[a] = b; } void dfs (int u, int p) { st[u] = 1; path.push_back(u); for (auto v: adj[u]) { if (v == p) continue; if (st[v] == 1) { for (int i = (int)path.size()-1; i >= 0; i--) { if (path[i] == v) break; uJoin(v, path[i]); } } if (st[v] == 0) dfs(v, u); } path.pop_back(); st[u] = 2; } void dfs2 (int u, int p) { st[u] = 1; for (auto v: adj[u]) { if (v == p) continue; if (uFind(u) != uFind(v)) cout << u+1 << ' ' << v+1 << '\n'; if (st[v] == 0) dfs2(v, u); } } int main() { setIO("std"); int n, m, u, v; cin >> n >> m; adj = vvi(n); st = vi(n, 0); par = vi(n); for (int i = 0; i < n; i++) par[i] = i; while (m--) { cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 0; i < n; i++) { if (st[i] == 0) dfs(i, -1); } st = vi(n, 0); for (int i = 0; i < n; i++) { if (st[i] == 0) dfs2(i, -1); } return 0; }

Compilation message (stderr)

pipes.cpp: In function 'void setIO(std::string)':
pipes.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((fileName + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pipes.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((fileName + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...