This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |