Submission #669508

#TimeUsernameProblemLanguageResultExecution timeMemory
669508arashMLGPipes (CEOI15_pipes)C++17
0 / 100
963 ms38000 KiB
// Link: https://oj.uz/problem/view/CEOI15_pipes // Status: NOT SOLVED #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ldb; typedef pair<int,int> pii; const int N = 1e6 + 2; const ll mod = 1e9+7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #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; int par[N][2],h[N],p[N]; int dp[N]; vector<int> G[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){ v = getPar(v,x),u = getPar(u,x); if(u == v) return false; par[v][x] = u; return true; } void dfs(int v) { bool ok = false; for(auto u : G[v]) { //cerr<<"YE"; if(h[u] == -1) { h[u] = h[v] + 1; p[u] = v; dfs(u); dp[v] += dp[u]; } else if(h[u] < h[v] && (ok || u != p[v])) { dp[v] ++; dp[u] --; } else if(u == p[v]) { ok = true; } } } int main() { cin.tie(nullptr)->sync_with_stdio(false); ms(h,-1); cin>>n>>m; for(int i = 1; i <= m; i ++) { cin>>a>>b; if(merge(a,b,0)) { G[a].pb(b); G[b].pb(a); } else if(merge(a,b,1)) { G[a].pb(b); G[b].pb(a); } } for(int i = 1; i <= n ; i++) { if(h[i] == -1) { h[i] = 0; p[i] = 0; dfs(i); } } for(int i = 1; i <= n; i ++) { if(dp[i] == 0 && p[i] != 0) { cout<<i << ' ' << p[i] <<'\n'; } } done; }
#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...