# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
27159 |
2017-07-09T17:23:35 Z |
bill_kondo |
Pipes (CEOI15_pipes) |
C++14 |
|
2056 ms |
13948 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;
static 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<int>adj[maxn];
static int h[maxn], low[maxn], cur;
static 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];
if(u == par) continue;
if(!mrk[u]){
dfs(u,v);
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)){
adj[a].pb(b);
adj[b].pb(a);
T[0].merge(a,b);
}
else if(T[1].root(a) != T[1].root(b)){
adj[a].pb(b);
adj[b].pb(a);
T[1].merge(a,b);
}
}
tarjan();
return 0;
}
Compilation message
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:51: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:70: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:77: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 |
Incorrect |
4 ms |
2688 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3172 KB |
Output is correct |
2 |
Incorrect |
8 ms |
3072 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
3064 KB |
Output is correct |
2 |
Incorrect |
154 ms |
2920 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
252 ms |
3784 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
420 ms |
5336 KB |
Output is correct |
2 |
Correct |
355 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
597 ms |
10608 KB |
Output is correct |
2 |
Incorrect |
528 ms |
7664 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
952 ms |
11872 KB |
Output is correct |
2 |
Incorrect |
917 ms |
9232 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1374 ms |
13948 KB |
Output is correct |
2 |
Incorrect |
1272 ms |
9828 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1683 ms |
13916 KB |
Output is correct |
2 |
Incorrect |
1549 ms |
9824 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2056 ms |
13360 KB |
Output is correct |
2 |
Correct |
1844 ms |
10948 KB |
Output is correct |