Submission #170315

#TimeUsernameProblemLanguageResultExecution timeMemory
170315ngmhPipes (CEOI15_pipes)C++11
40 / 100
473 ms65536 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pi; #define dep par1 #define low par2 int n, m, a, b, co, par1[100001], par2[100001]; vector<int> adj[100001]; inline int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) read_int() { int x = 0; char ch = getchar_unlocked(); while (ch < '0' || ch > '9') ch = getchar_unlocked(); while (ch >= '0' && ch <= '9'){ x = (x << 3) + (x << 1) + ch - '0'; ch = getchar_unlocked(); } return x; } int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) root(int *array, int x){ if(array[x] == -1) return x; return array[x] = root(array, array[x]); } void __attribute__((optimize("Ofast"), target("arch=sandybridge"))) connect(int *array, int x, int y){ array[root(array, x)] = root(array, y); adj[x].push_back(y); adj[y].push_back(x); } void __attribute__((optimize("Ofast"), target("arch=sandybridge"))) bridges(int x, int par){ if(dep[x] != -1) return; dep[x] = low[x] = co++; int t = 0; for(auto it:adj[x]){ if(it == par && t == 0){ t++; continue; } if(dep[it] != -1){ if(low[it] > dep[x]) cout << x << " " << it << "\n"; low[x] = min(low[x], low[it]); continue; } bridges(it, x); if(low[it] > dep[x]) cout << x << " " << it << "\n"; low[x] = min(low[x], low[it]); } } int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) main(){ ios_base::sync_with_stdio(false); cin.tie(0); memset(par1, -1, sizeof(par1)); memset(par2, -1, sizeof(par2)); n = read_int(); m = read_int(); for(int i = 0; i < m; i++){ a = read_int(); b = read_int(); if(a > b) swap(a, b); if(root(par1, a) != root(par1, b)) connect(par1, a, b); else if(root(par2, a) != root(par2, b)) connect(par2, a, b); } memset(par1, -1, sizeof(par1)); memset(par2, -1, sizeof(par2)); for(int i = 1; i <= n; i++) bridges(i, 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...