답안 #874365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874365 2023-11-16T18:09:35 Z AHOKA Pipes (CEOI15_pipes) C++14
0 / 100
2651 ms 10152 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h> 

using namespace std;

#define threesum cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
#define all(a) a.begin(), a.end()
#define lmx 9223372036854775807;
//#define mod 1000000007
#define F first
#define S second

vector<pair<int, int>> adj[100001];
int par[100001], par2[100001], edges, n, m, seen[100001], d[100001];

int getpar(int v){
    return ((par[v]!=v) ? par[v] = getpar(par[v]) : v);
}

int getpar2(int v){
    return ((par2[v]!=v) ? par2[v] = getpar2(par2[v]) : v);
}

bool merge(int u, int v){
    int u1 = getpar(u), v1 = getpar(v);
    if(u1 == v1){
		int u2 = getpar2(u), v2 = getpar2(v);
    	if(u2 == v2) return 0;
		par2[u2] = v2, edges++;
		return 1;
	}
	par[u1] = v1, edges++;
	return 1;
}

void dfs(int& v, pair<int, int> prev = {-1, -1}){
    seen[v] = 1;
    if (prev.first == -1)
        seen[v] = 0;
    d[v] = seen[v];
 
    for (auto& [u, id] : adj[v]){
         if (prev.first == u and prev.second == id)
            continue;
 
        d[v] = min(d[v], seen[u]);
 
        if (seen[u])
            continue;
 
        seen[u] = seen[v] + 1;
        dfs(u, {v, id});
        d[v] = min(d[v], d[u]);
 
        if (d[u] >= seen[u])
            printf("%d %d\n", u, v);
            
    }
}

int main() {
	cin >> n >> m;
	for(int i=1;i<=n;i++)par[i]=i, par2[i]=i;
	for(int i=0;i<m;i++){
		int u, v;cin >> v >> u;
		if(merge(u, v))adj[v].push_back({u, edges}), adj[u].push_back({v, edges});
	}
	//for(int i=1;i<=n;i++)if(!seen[i])dfs(i);
	cout << -1;
}

Compilation message

pipes.cpp: In function 'void dfs(int&, std::pair<int, int>)':
pipes.cpp:44:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |     for (auto& [u, id] : adj[v]){
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3928 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4444 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 257 ms 4372 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 378 ms 4700 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 637 ms 5592 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 805 ms 8384 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1294 ms 9040 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1704 ms 10152 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2160 ms 9920 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2651 ms 9844 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -