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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,k,n) for(int i=k;i<(int)(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> IP;
struct edge {
int from,to;
int cost;
edge(int t,int c) : to(t),cost(c) {}
edge(int f,int t,int c) : from(f),to(t),cost(c) {}
bool operator<(const edge &e) const {
return cost < e.cost;
}
};
int d[100005], _prev[100005], preindex[100005];
vector<int> get_path(int t) {
int index = -1;
vector<int> path;
for(;t!=-1;t=_prev[t]) {
index = preindex[t];
if(index != -1) path.push_back(index);
}
reverse(path.begin(),path.end());
return path;
}
class CsCourses {
public:
vector <int> getOrder(vector <int> theoreticalValue, vector <int> practicalValue, vector <int> expire, int skillBound) {
int n = theoreticalValue.size();
rep(i, 100005) {
d[i] = INF;
_prev[i] = -1;
preindex[i] = -1;
}
priority_queue<P, vector<P>, greater<P> > que;
que.push(mp(0, 0));
d[0] = 0;
while(que.size()) {
P p = que.top(); que.pop();
int cost = p.fi;
int a = p.se / 100;
int b = p.se % 100;
if(d[a * 100 + b] < cost) continue;
// cout << " --------- in queue ----- : " << cost << " now:" << p.se << endl;
rep(i, n) {
if(theoreticalValue[i] <= a + 1 && practicalValue[i] <= b + 1) {
int next = max(a, theoreticalValue[i]) * 100 + max(b, practicalValue[i]);
if(cost + 1 <= expire[i] && d[next] == cost + 1) {
vector<int> x = get_path(_prev[next]);
vector<int> y = get_path(a * 100 + b);
bool change = false;
if(x.size() == y.size()) {
rep(i, min(x.size(), y.size())) {
if(x[i] == y[i]) continue;
if(x[i] < y[i]) break;
else {
change = true;
break;
}
}
} else if(y.size() < x.size()) {
change = true;
}
if(change) {
_prev[next] = a * 100 + b;
preindex[next] = i;
que.push(mp(cost + 1, next));
}
}
if(cost + 1 <= expire[i] && d[next] > cost + 1) {
d[next] = cost + 1;
_prev[next] = a * 100 + b;
preindex[next] = i;
que.push(mp(cost + 1, next));
}
}
}
}
bool first = true;
vector<int> ret;
REP(i, skillBound, 55) {
REP(j, skillBound, 55) {
if(d[i * 100 + j] == INF) continue;
vector<int> x = get_path(i * 100 + j);
if(first) {
ret = x;
first = false;
} else {
if(ret.size() == x.size()) {
rep(i, min(ret.size(), x.size())) {
if(ret[i] == x[i]) continue;
if(ret[i] < x[i]) break;
else {
swap(ret, x);
break;
}
}
} else if(ret.size() > x.size()) {
ret = x;
}
}
}
}
rep(i, ret.size()) cout << ret[i] << " ";
cout << endl;
return ret;
}
};
|