Submission #396316

#TimeUsernameProblemLanguageResultExecution timeMemory
396316The_BlitzPipes (CEOI15_pipes)C++17
90 / 100
1390 ms22520 KiB
// Restart // += O(logn) ; + = O(n) #include<vector> #include<iostream> #define fastio ios_base::sync_with_stdio(0);cin.tie(0) using namespace std; vector<int> G[100005]; int g_low[100005]; int g_num[100005]; int P[2][100005]; int n; int cont = 1; void dsu(int z){ for(int i=1; i<=n;i++){ P[z][i] = i; } } int dsu_find(int z, int x){ if(x==P[z][x]) return x; P[z][x] = dsu_find(z,P[z][x]); return P[z][x]; } bool dsu_uni(int z, int a , int b){ int x = dsu_find(z,a); int y = dsu_find(z,b); if(x==y) return false; P[z][y] = x; G[a].push_back(b); G[b].push_back(a); return true; } void dfs(int x ,int p = -1){ // p: parent g_low[x]=g_num[x]=cont++; // low:component ; num:visit order for(int v : G[x]){ if(v == p) continue; if(g_num[v]==-1){ dfs(v,x); if(g_low[v] > g_num[x] && dsu_find(1,v) != dsu_find(1,x)){ cout<< x << " " << v << "\n"; } g_low[x]=min(g_low[x],g_low[v]); } g_low[x]=min(g_low[x],g_num[v]); } } void go(){ int m; cin>>n>>m; for(int i=1;i<=n;i++){ g_low[i] = -1; g_num[i] = -1; P[0][i] = i; P[1][i] = i; } for(int i=1;i<=m;i++){ int x,y; cin>>x>>y; if(!dsu_uni(0,x,y)){ dsu_uni(1,x,y); } } for(int i=1;i<=n;i++){ if(g_num[i] == -1) dfs(i); } } int main() { fastio; go(); return 0; }
#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...