Submission #633897

#TimeUsernameProblemLanguageResultExecution timeMemory
633897Do_you_copySenior Postmen (BOI14_postmen)C++17
0 / 100
2 ms2684 KiB
#include <bits/stdc++.h> //#define int long long #define fi first #define se second #define pb push_back #define faster ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; using ll = long long; using ull = unsigned ll; using ld = long double; using pii = pair <int, int>; using pil = pair <int, ll>; using pli = pair <ll, int>; using pll = pair <ll, ll>; mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count()); ll min(const ll &a, const ll &b){ return (a < b) ? a : b; } ll max(const ll &a, const ll &b){ return (a > b) ? a : b; } //const ll Mod = 1000000007; //const ll Mod2 = 999999999989; //only use when required const int maxN = 1e5 + 1; int n, m; vector <pii> adj[maxN]; int cur[maxN]; bool visited[maxN]; bool vis[maxN]; int cycle; vector <vector <int>> ans; void dfs(int u, int p){ for (; cur[u] < adj[u].size(); ++cur[u]){ pii i = adj[u][cur[u]]; int v = i.fi; if (v == p || vis[i.se]) continue; visited[u] = 1; vis[i.se] = 1; if (visited[v]){ cycle = v; ans.pb({u}); visited[u] = 0; return; } //if (u == 3) cerr << v << "!"; dfs(v, u); if (cycle){ ans.back().pb(u); visited[u] = 0; if (cycle != u) return; else{ cycle = 0; } } } } void Init(){ cin >> n >> m; for (int i = 1; i <= m; ++i){ int u, v; cin >> u >> v; adj[u].pb({v, i}); adj[v].pb({u, i}); } for (int i = 1; i <= n; ++i){ if (cur[i] < adj[i].size()) dfs(i, 0); } cout << ans.size() << "\n"; for (auto &i: ans){ for (int &j: i) cout << j << " "; cout << "\n"; } } #define debu #define taskname "test" signed main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); #ifdef debug freopen(taskname".out", "w", stdout); #endif } faster; ll tt = 1; //cin >> tt; while (tt--){ Init(); } if (fopen("timeout.txt", "r")){ ofstream timeout("timeout.txt"); timeout << 1000 * double(clock()) / CLOCKS_PER_SEC; #ifndef debug cerr << "\nTime elapsed: " << 1000 * double(clock()) / CLOCKS_PER_SEC << "ms\n"; #endif } }

Compilation message (stderr)

postmen.cpp: In function 'void dfs(int, int)':
postmen.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (; cur[u] < adj[u].size(); ++cur[u]){
      |            ~~~~~~~^~~~~~~~~~~~~~~
postmen.cpp: In function 'void Init()':
postmen.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         if (cur[i] < adj[i].size())
      |             ~~~~~~~^~~~~~~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...