File tree Expand file tree Collapse file tree 1 file changed +16
-27
lines changed Expand file tree Collapse file tree 1 file changed +16
-27
lines changed Original file line number Diff line number Diff line change @@ -31,39 +31,28 @@ typedef long long ll;
31
31
#define fk (b ) for (int k=0 ; k < ((int )(b)); k++) // k -> [0, b)
32
32
#define fke (b ) for (int k=0 ; k < ((int )(b)); k++) // k -> [0, b]
33
33
#define fle (b ) for (int l=0 ; l <= ((int )(b)); l++) // l -> [0, b]
34
- int n;
35
- vi visited (55 , 0 );
36
- vs M;
37
- void dfs (int s){
38
- fi (n){
39
- if (M[s][i] == ' Y' && !visited[i]){
40
- visited[i] = 1 ;
41
- dfs (i);
42
- }
43
- }
44
- }
45
34
46
35
class XorTravelingSalesman {
47
36
48
37
public:
49
38
int maxProfit (vector <int > cityValues, vector <string> roads){
50
39
51
- M = roads ;
52
-
53
- bool dp[ 1050 ] = { 0 } ;
54
- n = cityValues. size () ;
55
- int ret = 0 ;
56
- visited[ 0 ] = 1 ;
57
- dfs ( 0 );
58
-
59
- fj (n){
60
- if (visited[j] == 0 ) continue ;
61
- int c = cityValues[j];
62
- dp[c] = 1 ;
63
- fi ( 1024 ){
64
- int k = (i^c) ;
65
- dp[ k] |= dp[i] ;
66
- if (dp[k]) ret = max (ret , k);
40
+ int n = cityValues. size (), ret = 0 ;
41
+ int visited[ 55 ][ 1050 ];
42
+ visited[ 0 ][cityValues[ 0 ]] = 1 ;
43
+ queue<pi> Q ;
44
+ Q. push ( mp ( 0 , cityValues[ 0 ])) ;
45
+ while (!Q. empty ()){
46
+ pi p = Q. front ( );
47
+ Q. pop ();
48
+ int i = p. first , r = p. second ;
49
+ ret = max (ret, r) ;
50
+ fj (n){
51
+ if (roads[i][j] == ' N ' ) continue ;
52
+ int k = r^cityValues[j];
53
+ if (visited[j][k]) continue ;
54
+ visited[j][ k] = 1 ;
55
+ Q. push ( mp (j , k) );
67
56
}
68
57
}
69
58
return ret;
You can’t perform that action at this time.
0 commit comments