Submission #146322

#TimeUsernameProblemLanguageResultExecution timeMemory
146322evpipisPipes (CEOI15_pipes)C++98
20 / 100
1839 ms14012 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; const int len = 1e5+3; int n, m, cnt; int par[len], num[len], low[len]; vector<int> adj[len]; vector<ii> vec; struct dsu{ int anc[len]; void init(){ for (int i = 1; i <= n; i++) anc[i] = i; } int fin(int i){ if (anc[i] == i) return i; return anc[i] = fin(anc[i]); } void join(int i, int j){ i = fin(i), j = fin(j); if (i != j) anc[j] = i; } }; dsu one, two; void dfs(int u){ num[u] = low[u] = ++cnt; for (int j = 0; j < adj[u].size(); j++){ int v = adj[u][j]; if (!num[v]){ par[v] = u; dfs(v); if (low[v] > num[u]) printf("%d %d\n", u, v); low[u] = min(low[u], low[v]); } else if (v != par[u]){ low[u] = min(low[u], num[v]); } } } int main(){ scanf("%d %d", &n, &m); one.init(); two.init(); for (int i = 0; i < m; i++){ int a, b; scanf("%d %d", &a, &b); if (one.fin(a) != one.fin(b)){ vec.pb(mp(a, b)); one.join(a, b); } else if (two.fin(a) != two.fin(b)){ vec.pb(mp(a, b)); two.join(a, b); } } for (int i = 0; i < vec.size(); i++){ int a = vec[i].fi, b = vec[i].se; adj[a].pb(b); adj[b].pb(a); } for (int i = 1; i <= n; i++) if (!num[i]) dfs(i); return 0; }

Compilation message (stderr)

pipes.cpp: In function 'void dfs(int)':
pipes.cpp:40:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < adj[u].size(); j++){
                     ~~^~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
pipes.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
#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...