답안 #669288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
669288 2022-12-06T08:06:29 Z manizare Pipes (CEOI15_pipes) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end() 
#define pb push_back
using namespace std ;
const int maxn = 1e5+100 , maxq =5002 , inf = 2e17 + 100 , mod = 1e9 + 7 ;
vector <int >G[maxn] ;
int par[maxn] , par2[maxn] , p[maxn] , dp[maxn] , mark[maxn] , dis[maxn];
int find(int v){
	if(par[v] == v)return v; 
	return par[v] = find(par[v]);
}
int find2(int v){
	if(par2[v] == v)return v; 
	return par2[v] = find2(par2[v]) ;
}

void dfs(int v){
	mark[v] = 1; 
	for(int i = 0 ; i < G[v].size() ; i++){
		int u = G[v][i] ;
		if(mark[u] == 1){
			if(dis[u] < (dis[v] - 1) {
				dp[v] ++ ;
				dp[u]--;
			}
			continue ;
		}
		dis[u] = dis[v] + 1; 
		p[u] = v; 
		dfs(u);
		dp[v] += dp[u] ;
	}
}

signed main(){	
	ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
	int n , m ;
	cin >> n >> m ;
	for(int i= 1 ; i <= n ; i++){
		par[i] = i ;
		par2[i] = i ; 
	}
	for(int i =1 ; i <= m ; i++){
		int v  , u ;
		cin >> v >> u ;
		int v1 = find(v) , u1 = find(u);
		if(v1 != u1){
			G[v].pb(u) ;
			G[u].pb(v);
			par[v1] = u1 ;
		}else if(find2(v) != find2(u)){
			par2[find2(v)] = find2(u);
			G[v].pb(u) ;
			G[u].pb(v);
		}
	}
	for(int i = 1; i <= n ; i++){
		if(mark[i] == 0)dfs(i); 
	}
	for(int i = 1; i <= n ; i++){
		if(dp[i] == 0 && p[i] != 0){
			cout << i << " " << p[i] << "\n";
		}
	}
}

Compilation message

pipes.cpp:5:52: warning: overflow in conversion from 'double' to 'int' changes value from '2.000000000000001e+17' to '2147483647' [-Woverflow]
    5 | const int maxn = 1e5+100 , maxq =5002 , inf = 2e17 + 100 , mod = 1e9 + 7 ;
      |                                               ~~~~~^~~~~
pipes.cpp: In function 'void dfs(int)':
pipes.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i = 0 ; i < G[v].size() ; i++){
      |                  ~~^~~~~~~~~~~~~
pipes.cpp:22:7: warning: init-statement in selection statements only available with '-std=c++17' or '-std=gnu++17'
   22 |    if(dis[u] < (dis[v] - 1) {
      |       ^~~
pipes.cpp:22:28: error: expected ';' before '{' token
   22 |    if(dis[u] < (dis[v] - 1) {
      |                            ^~
      |                            ;
pipes.cpp:22:14: warning: statement has no effect [-Wunused-value]
   22 |    if(dis[u] < (dis[v] - 1) {
      |       ~~~~~~~^~~~~~~~~~~~~~
pipes.cpp:26:4: error: expected primary-expression before 'continue'
   26 |    continue ;
      |    ^~~~~~~~
pipes.cpp:25:5: error: expected ')' before 'continue'
   25 |    }
      |     ^
      |     )
   26 |    continue ;
      |    ~~~~~~~~
pipes.cpp:22:6: note: to match this '('
   22 |    if(dis[u] < (dis[v] - 1) {
      |      ^