# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
27160 |
2017-07-09T17:29:05 Z |
bill_kondo |
Pipes (CEOI15_pipes) |
C++14 |
|
1967 ms |
15900 KB |
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define debug(args...) fprintf(stderr,args)
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define REP(i,a,b) for(int i = a; i >= b; --i)
typedef long long ll;
typedef pair<int,int>pii;
const int maxn = 1e5 + 10;
int n, m;
struct dsu{
int par[maxn];
int sz[maxn];
void init(){
FOR(i,1,n){
par[i] = i;
sz[i] = 1;
}
}
int root(int v){
if(par[v] == v) return v;
return root(par[v]);
}
void merge(int x, int y){
x = root(x);
y = root(y);
if(x == y) return;
if(sz[y] > sz[x]) swap(x,y);
par[y] = x;
sz[x] += sz[y];
}
} T[2];
vector<pii>adj[maxn];
int cnt;
int h[maxn], low[maxn], cur;
bool mrk[maxn];
void dfs(int v, int par){
mrk[v] = true;
low[v] = h[v] = ++cur;
for(int i = 0; i < adj[v].size(); ++i){
int u = adj[v][i].first;
int e = adj[v][i].second;
if(e == par) continue;
if(!mrk[u]){
dfs(u,e);
low[v] = min(low[v],low[u]);
if(low[u] > h[v]) printf("%d %d\n",u,v);
}
else low[v] = min(low[v],h[u]);
}
}
void tarjan(){
FOR(i,1,n)
if(!mrk[i])
dfs(i,-1);
}
int main(){
scanf("%d%d",&n,&m);
T[0].init();
T[1].init();
FOR(i,1,m){
int a, b;
scanf("%d%d",&a,&b);
if(T[0].root(a) != T[0].root(b)){
++cnt;
adj[a].pb(pii(b,cnt));
adj[b].pb(pii(a,cnt));
T[0].merge(a,b);
}
else if(T[1].root(a) != T[1].root(b)){
++cnt;
adj[a].pb(pii(b,cnt));
adj[b].pb(pii(a,cnt));
T[1].merge(a,b);
}
}
assert(cnt <= n + n);
tarjan();
return 0;
}
Compilation message
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj[v].size(); ++i){
~~^~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:72:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
pipes.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
3456 KB |
Output is correct |
2 |
Correct |
8 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
3156 KB |
Output is correct |
2 |
Correct |
134 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
244 ms |
3968 KB |
Output is correct |
2 |
Correct |
298 ms |
3708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
410 ms |
5816 KB |
Output is correct |
2 |
Correct |
366 ms |
5492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
639 ms |
12132 KB |
Output is correct |
2 |
Correct |
547 ms |
9080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
965 ms |
13320 KB |
Output is correct |
2 |
Correct |
914 ms |
10140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1373 ms |
15900 KB |
Output is correct |
2 |
Correct |
1254 ms |
11820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1714 ms |
15900 KB |
Output is correct |
2 |
Correct |
1532 ms |
11828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1967 ms |
15356 KB |
Output is correct |
2 |
Correct |
1835 ms |
11968 KB |
Output is correct |