Submission #19280456


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<404040> uf;
int C[404040];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x>>y;
		x=uf[x];
		y=uf[y];
		if(x==y) {
			C[x]++;
		}
		else {
			C[x]=C[y]=C[x]+C[y]+1;
			uf(x,y);
		}
	}
	
	int ret=0;
	FOR(i,401010) if(uf[i]==i) {
		ret+=min(uf.count(i),C[i]);
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task B - Reversible Cards
User kmjp
Language C++ (GCC 9.2.1)
Score 400
Code Size 1739 Byte
Status AC
Exec Time 79 ms
Memory 12712 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:35:8: warning: unused variable ‘j’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:35:10: warning: unused variable ‘k’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:35:12: warning: unused variable ‘l’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:35:14: warning: unused variable ‘r’ [-Wunused-variable]
   35 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:63:38: note: in expansion of macro ‘FOR’
   63 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt
Case Name Status Exec Time Memory
0_000.txt AC 14 ms 8044 KB
0_001.txt AC 13 ms 8108 KB
0_002.txt AC 14 ms 8084 KB
1_003.txt AC 10 ms 8064 KB
1_004.txt AC 13 ms 8112 KB
1_005.txt AC 39 ms 8004 KB
1_006.txt AC 13 ms 8072 KB
1_007.txt AC 15 ms 8036 KB
1_008.txt AC 38 ms 8056 KB
1_009.txt AC 79 ms 9512 KB
1_010.txt AC 76 ms 9440 KB
1_011.txt AC 69 ms 9444 KB
1_012.txt AC 45 ms 9584 KB
1_013.txt AC 43 ms 9464 KB
1_014.txt AC 41 ms 8048 KB
1_015.txt AC 46 ms 12712 KB
1_016.txt AC 11 ms 8008 KB
1_017.txt AC 17 ms 8232 KB
1_018.txt AC 29 ms 8152 KB
1_019.txt AC 60 ms 8896 KB
1_020.txt AC 63 ms 8760 KB
1_021.txt AC 9 ms 8036 KB
1_022.txt AC 10 ms 8004 KB
1_023.txt AC 53 ms 8664 KB
1_024.txt AC 36 ms 8592 KB
1_025.txt AC 65 ms 8892 KB
1_026.txt AC 42 ms 8656 KB