답안 #668737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
668737 2022-12-04T20:32:17 Z KiaRez Pipes (CEOI15_pipes) C++17
30 / 100
1074 ms 36132 KB
/*
                                                  IN THE NAME OF GOD
	...........................................................................................................................
	...........................................................................................................................
	.......@..........@....@@@@@@@@@............@..............@@@@@@@@@@........@@@@@@@@@@@.......@@@@@@@@@@@@@@@@@...........
	.......@........@..........@...............@.@.............@........@........@................................@............
	.......@......@............@..............@...@............@........@........@..............................@..............
	.......@....@..............@.............@.....@...........@........@........@............................@................
	.......@..@................@............@.......@..........@@@@@@@@@@........@..........................@..................
	.......@.@.................@...........@@@@@@@@@@@.........@...@.............@@@@@@@@@@@..............@....................
	.......@....@..............@..........@...........@........@....@............@......................@......................
	.......@.......@...........@.........@.............@.......@.....@...........@....................@........................
	.......@.........@.........@........@...............@......@......@..........@..................@..........................
	.......@...........@...@@@@@@@@@...@.................@.....@.......@.........@@@@@@@@@@@@......@@@@@@@@@@@@@@@.............
	...........................................................................................................................
	...........................................................................................................................
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef pair<pii, int> piii;
typedef pair<ll, pll> lpll;
typedef pair<pll, ll> plll;
typedef pair<pii, pii> piipii;
typedef pair<pll, pll> pllpll;
typedef long double ld;

#define SP                                     ' '
#define endl                                   '\n'
#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define DASH                                   "---------"
#define UNDERLINE                              "_________"
#define all(x)                                 (x).begin(),(x).end()
#define FORD(i, s, e)                          for(int i=s; i>=e; --i)
#define FOR(i, s, e)                           for(int i=s; i<=e; ++i)
#define kill(x)		                           cout << x << '\n', exit(0);
#define set_dec(x)	                           cout << fixed << setprecision(x);
#define fuck(x)                                cout << #x << " : " << x << endl
#define ios				                       ios_base::sync_with_stdio(false), cin.tie(0)
#define file_io(x,y)	                       freopen(x, "r", stdin); freopen(y, "w", stdout);

const int N = 232323;
const ll MOD = 1e9+7;

ll getmod(ll a, ll mod=MOD)                    {return (a+mod)%mod;}
ll max(ll a, ll b)                             {return (a>b ? a : b);}
ll min(ll a, ll b)                             {return (a<b ? a : b);}
ll abso(ll a)                                  {return (a<0?-a:a);}

int n, A[N], par[N][2], m, low[N], lay[N], mark[N], ind;
vector<pii> adj[N]; vector<pii> ans;

int getPar(int v, int ind) {return (par[v][ind]==0 ? v : par[v][ind]=getPar(par[v][ind], ind));}
void update(int v, int u, int ind) {v=getPar(v, ind), u=getPar(u, ind);if (v==u){return;}par[v][ind]=u;}

void dfs(int v, int l, int p, int index){
	mark[v]=1, lay[v]=l;
	for(auto it : adj[v]) {
		if (!mark[it.F]) {dfs(it.F, l+1, v, it.S); low[v]=min(low[v], low[it.F]);}
		else if (mark[it.F] && it.S!=index) {low[v]=min(low[v], lay[it.F]);}
	}
	if (low[v] > lay[p] && p!=0) {
		ans.pb({v, p});
	}
}

int main () {
    ios;

    cin>>n>>m; fill(low, low+n+10, 1e9);
	FOR(i, 1, m){
		int v, u;cin>>v>>u;
		if (getPar(v, 0) != getPar(u, 0)) {update(v, u, 0); adj[v].pb({u, ++ind}); adj[u].pb({v, ind});}
		else if (getPar(v, 1) != getPar(u, 1)) {update(v, u, 1); adj[v].pb({u, ++ind}); adj[u].pb({v, ind});}
	}

	FOR(i, 1, n) {if (!mark[i]) {dfs(i, 1, 0, 0);}}

	for(auto it : ans) {cout << min(it.F, it.S) << ' ' << max(it.F, it.S) << endl;}

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6356 KB Output is correct
2 Correct 6 ms 6100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 11292 KB Output is correct
2 Correct 85 ms 11340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 16360 KB Output is correct
2 Runtime error 173 ms 17852 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 259 ms 24776 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 390 ms 19028 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 540 ms 28832 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 758 ms 36132 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 901 ms 35744 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1074 ms 27576 KB Memory limit exceeded
2 Halted 0 ms 0 KB -