답안 #684383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684383 2023-01-21T05:37:52 Z doni Kutije (COCI21_kutije) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second

ll parent[1001];
ll rank[1001];

void make_set(ll v) {
	parent[v] = v;
	rank[v] = 0;
}
 
ll find_set(ll v) {
	if (v == parent[v])
		return v;
	return parent[v] = find_set (parent[v]);
}
 
void union_sets(ll a, ll b) {
	a = find_set (a);
	b = find_set (b);
	if (a != b) {
		if (rank[a] < rank[b])
			swap (a, b);
		parent[b] = a;
		if (rank[a] == rank[b])
			++rank[a];
	}
}

void bf(){
    ll n,a,b,m,q;
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++){
    	make_set(i);
	}
    for(int mm=0;mm<m;mm++){
	    for(int i=0;i<n;i++){
	    	cin>>a;
	    	union_sets(a,i+1);
		}
	}
	for(int i=0;i<q;i++){
		cin>>a>>b;
		if(find_set(a)==find_set(b)){
			cout<<"DA"<<endl;
		}
		else{
			cout<<"NE\n";
		}
		
	}
}

/*
 
*/

int main(){
//	ll t;cin>>t;while(t--)
		bf();
}

Compilation message

Main.cpp: In function 'void make_set(long long int)':
Main.cpp:12:2: error: reference to 'rank' is ambiguous
   12 |  rank[v] = 0;
      |  ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
Main.cpp:8:4: note:                 'long long int rank [1001]'
    8 | ll rank[1001];
      |    ^~~~
Main.cpp: In function 'void union_sets(long long int, long long int)':
Main.cpp:25:7: error: reference to 'rank' is ambiguous
   25 |   if (rank[a] < rank[b])
      |       ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
Main.cpp:8:4: note:                 'long long int rank [1001]'
    8 | ll rank[1001];
      |    ^~~~
Main.cpp:25:17: error: reference to 'rank' is ambiguous
   25 |   if (rank[a] < rank[b])
      |                 ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
Main.cpp:8:4: note:                 'long long int rank [1001]'
    8 | ll rank[1001];
      |    ^~~~
Main.cpp:28:7: error: reference to 'rank' is ambiguous
   28 |   if (rank[a] == rank[b])
      |       ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
Main.cpp:8:4: note:                 'long long int rank [1001]'
    8 | ll rank[1001];
      |    ^~~~
Main.cpp:28:18: error: reference to 'rank' is ambiguous
   28 |   if (rank[a] == rank[b])
      |                  ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
Main.cpp:8:4: note:                 'long long int rank [1001]'
    8 | ll rank[1001];
      |    ^~~~
Main.cpp:29:6: error: reference to 'rank' is ambiguous
   29 |    ++rank[a];
      |      ^~~~
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from Main.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: candidates are: 'template<class> struct std::rank'
 1359 |     struct rank
      |            ^~~~
Main.cpp:8:4: note:                 'long long int rank [1001]'
    8 | ll rank[1001];
      |    ^~~~