제출 #771806

#제출 시각아이디문제언어결과실행 시간메모리
771806Mohammad_Parsa조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2)C++17
1 / 100
448 ms468 KiB
/* in the name of allah */
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define F first
#define S second
#define mk make_pair
typedef long long ll;

const int N=50+7;
int a[N][N];

int main(){
	ios:: sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,q;
	cin>>n;
	cin>>q;
	int ans=0;
	while(q--){
		int v,u;
		cin>>v>>u;
		if(a[v][u]==0)ans++;
		a[v][u]=1;
		int k=1;
		while(k){
			k=0;
			for(int x=1;x<=n;x++){
				for(int y=1;y<=n;y++){
					for(int z=1;z<=n;z++){
						if(a[x][y] && z!=x && a[x][z]==0 && a[y][z] && a[z][y]){
							k=1;
							a[x][z]=1;
							ans++;
						}
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...