-
Notifications
You must be signed in to change notification settings - Fork 0
/
duckvirus.cpp
87 lines (82 loc) · 1.93 KB
/
duckvirus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <time.h>
using namespace std;
int array3[100]; // answer
clock_t before;
int main(int argc , char* argv[]){
unsigned int cnt=0,index=0;
before = clock();
cin >> cnt;
unsigned int position;
int array[100][100];
int array1[100][100];
int array2[100];
int array3[100];
unsigned int friend_cnt = 0,virus=0;
while(cnt--){
int friend_cnt = 0;
cin >> friend_cnt;
//cout << "friend count: " << friend_cnt<< endl;
memset(array,0x00,100*100);
memset(array1,0x00,100*100);
for(int i=0;i<friend_cnt;i++){
for(int j=0;j<friend_cnt;j++){
cin >> array[i][j];
// cout << array[i][j] << " ";
}
// cout << endl;
}
cin >> virus;
for(int i=0;i<virus;i++){
for(int j=0;j<2;j++){
cin >> array1[i][j];
// cout << array1[i][j] << " ";
}
// cout << endl;
}
int rcnt=0,cocnt=0;
for(int i=0;i<virus;i++){
rcnt =0,cocnt=0;
memset(array3,0x00,100);
memset(array2,0x00,100);
array3[cocnt++] = array1[i][0];
array3[cocnt++] = array1[i][1];
//cout << "new line" << endl;
for(int j=0;j<cocnt;j++){
for(int k=0;k<friend_cnt;k++){
if(array[array1[i][j]-1][k] == 1) {
array2[rcnt++] = k+1;
}
}
// cout << "rcnt " << rcnt << endl;
for(int l=0;l<rcnt;l++){
if(rcnt<3)
break;
for(int m=l+1;m<rcnt;m++){
if(array2[l] == array2[m]){
int already = 0;
for(int n=0;n<cocnt;n++)
if(array3[n] == array2[l]){
already = 1;
break;
}
if(already ==0 ) {
array3[cocnt++]=array2[l];
array1[i][cocnt-1] = array2[l];
// cout << "added " << array1[i][cocnt-1]<<endl;
}
}
}
}
}
cout<<cocnt<<" ";
}
cout<<endl;
}
double result = (double)(clock() - before);// / CLOCKS_PER_SEC;
cout<< "excution time " << result << endl;
}