답안 #244557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244557 2020-07-04T09:40:06 Z oolimry Potemkin cycle (CEOI15_indcyc) C++14
컴파일 오류
0 ms 0 KB
//HAPPY BIRTHDAY!!!
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;

int depth[1005];
vector<int> adj[1005];
vector<int> paths[1005];
vector<int> p[1005];
vector<ii> backs;
void dfs(int u){
	for(int v : adj[u]){
		if(depth[v] != 0){
			if(depth[v] < depth[u]-1){ ///back edge
				int dist = depth[u] - depth[v];
				backs.push_back(ii(dist, u));
			}
		}
		else{
			depth[v] = depth[u] + 1;
			paths[v].push_back(u);
			p[v] = u;
			dfs(v);
		}
	}
}

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n, m; cin >> n >> m;
	
	for(int i = 0;i < m;i++){
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	for(int i = 1;i <= n;i++){
		if(depth[i] != 0) continue; ///visited;
		backs.clear();
		
		depth[i] = 1;
		dfs(i);
		
		sort(backs.begin(), backs.end());
		for(ii e : backs){
			//cout << e.first << " " << e.second << ":" << endl;
			int u = e.second;
			int targetDepth = depth[u] - e.first;
			//cout << targetDepth << "\n";
			
			vector<int> P;
			while(depth[u] != targetDepth){
				P.push_back(u);
				
				for(int i = (int) (paths[u].size()-1);i >= 0;i--){
					int v = paths[u][i];
					//cout << u << " " << v << endl;
					
					if(depth[v] >= targetDepth){
						u = v;
						break;
					}
				}
			}
			
			P.push_back(u);
			
			if((int) P.size() >= 3){
				for(int x : P) cout << x << " ";
				return 0;
			}
			else{
				paths[e.second].push_back(u);
			}
		
		}
	}
	
	cout << "no";
}

Compilation message

indcyc.cpp: In function 'void dfs(int)':
indcyc.cpp:22:11: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'int')
    p[v] = u;
           ^
In file included from /usr/include/c++/7/vector:69:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from indcyc.cpp:2:
/usr/include/c++/7/bits/vector.tcc:179:5: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]
     vector<_Tp, _Alloc>::
     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/7/bits/vector.tcc:179:5: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from indcyc.cpp:2:
/usr/include/c++/7/bits/stl_vector.h:461:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]
       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
       ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:461:7: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
/usr/include/c++/7/bits/stl_vector.h:482:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]
       operator=(initializer_list<value_type> __l)
       ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:482:7: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'