# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
668105 |
2022-12-02T18:35:41 Z |
arashMLG |
Pipes (CEOI15_pipes) |
C++17 |
|
1004 ms |
61972 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef pair<ll,ll> pii;
const int N = 1e6 + 2;
const ll mod = 1e9+7;
#define F first
#define S second
#define pb push_back
#define ms(x,y) memset((x) , (y) , sizeof (x))
#define done return cout<<endl , 0;
#define kill(x) cout<<x; exit(0);
#define isIn(x,s,e) ((x) >= (s) && (x) <= e)
//#define int ll
ll pw(ll a, ll b, ll md = mod){ll res = 1; while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n,m,a,b;
vector<int> G[N];
int par[N][2],p[N];
int dp[N],dist[N];
bool mark[N];
int getPar(int v, int x) {
return par[v][x] == 0 ? v : par[v][x] = getPar(par[v][x],x);
}
bool merge(int v, int u,int x) {
int vp = getPar(v,x),up= getPar(u,x); if(up == vp) return false; par[vp][x] = up; G[v].pb(u); G[u].pb(v);return true;
}
void dfs(int v,int dad) {
mark[v] = true;
for(int u : G[v]) {
if(!mark[v]) {
cerr<<v << " -> " << u << '\n';
dist[u] = dist[v] + 1;
p[u] = v;
dfs(u,v);
dp[v] += dp[u];
} else if(dist[u] < dist[v] && u != dad) {
dp[v] ++;
dp[u] --;
}
}
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(0);
cin>>n>>m;
for(int i = 0; i < m ; i ++) {
cin>>a>>b;
if(!merge(a,b,0)) {
merge(a,b,1);
}
}
for(int i = 1; i <= n; i ++) {
if(!mark[i]) {
dfs(i,-1);
p[i] = i;
}
}
for(int i = 1; i <= n ; i ++) {
if(dp[i] == 0 && p[i] != i) {
cout<< i << ' '<< p[i] <<'\n';
}
}
done;
}
/*
10 11
1 7
1 8
1 6
2 8
6 7
5 8
2 5
2 3
2 4
3 4
10 9
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
23764 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
24124 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
103 ms |
29468 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
162 ms |
33852 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
276 ms |
41192 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
368 ms |
48124 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
539 ms |
37236 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
715 ms |
42784 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
873 ms |
49048 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1004 ms |
61972 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |