Submission #69464951


Source Code Expand

#include <bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using namespace atcoder;
#define all(a) a.begin(),a.end()
#define compress(a) sort(all(a));a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef modint1000000007 mi;
typedef pair<ll,ll> P;
constexpr ll mod=1000000007;
constexpr ll inf=3e18;

int main(){
	int n;
	cin>>n;
	vector<int>a(n),b(n);
	rep(i,n)cin>>a[i]>>b[i];
	vector<vector<int>>G(n);
	queue<int>q;
	vector<int>res(n,-1);
	rep(i,n){
		if(a[i]==0&&b[i]==0){
			q.push(i);
			res[i]=1;
		}
		else{
			G[a[i]-1].push_back(i);
			G[b[i]-1].push_back(i);
		}
	}
	while(q.size()){
		int v=q.front();
		q.pop();
		for(auto &e:G[v]){
			if(res[e]==-1){
				res[e]=1;
				q.push(e);
			}
		}
	}
	int ans=0;
	rep(i,n)if(res[i]==1)ans++;
	cout<<ans<<endl;
}

Submission Info

Submission Time
Task C - New Skill Acquired
User Rho17
Language C++ 20 (gcc 12.2)
Score 300
Code Size 867 Byte
Status AC
Exec Time 108 ms
Memory 16532 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 30
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand_01.txt AC 1 ms 3524 KiB
hand_02.txt AC 1 ms 3516 KiB
random_01.txt AC 94 ms 15876 KiB
random_02.txt AC 5 ms 3896 KiB
random_03.txt AC 100 ms 16128 KiB
random_04.txt AC 70 ms 12640 KiB
random_05.txt AC 97 ms 16136 KiB
random_06.txt AC 70 ms 12980 KiB
random_07.txt AC 97 ms 15856 KiB
random_08.txt AC 35 ms 10336 KiB
random_09.txt AC 104 ms 16532 KiB
random_10.txt AC 99 ms 16376 KiB
random_11.txt AC 80 ms 16300 KiB
random_12.txt AC 97 ms 16388 KiB
random_13.txt AC 96 ms 16352 KiB
random_14.txt AC 97 ms 16332 KiB
random_15.txt AC 108 ms 16392 KiB
random_16.txt AC 39 ms 9076 KiB
random_17.txt AC 85 ms 14328 KiB
random_18.txt AC 10 ms 4788 KiB
random_19.txt AC 41 ms 8980 KiB
random_20.txt AC 63 ms 11572 KiB
random_21.txt AC 2 ms 3732 KiB
random_22.txt AC 20 ms 5820 KiB
random_23.txt AC 77 ms 13432 KiB
random_24.txt AC 24 ms 6636 KiB
random_25.txt AC 42 ms 9072 KiB
random_26.txt AC 4 ms 3776 KiB
sample_01.txt AC 1 ms 3636 KiB
sample_02.txt AC 1 ms 3572 KiB