-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathprojec management.cpp
51 lines (48 loc) · 1.02 KB
/
projec management.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
# include <fstream>
# include <algorithm>
# include <vector>
# include <queue>
# define inf 999999999
using namespace std;
ifstream f("pm2.in");
ofstream g("pm2.out");
vector <int> v[105];
queue <int> q;
int i,j,n,k,VV,var;
int minn[105],maxx[105],timp[105],in[105],out[105];
void BF ()
{
while (! q.empty())
{
k=q.front(); q.pop();
VV=max(VV, minn[k]+timp[k]);
for (i=0; i<v[k].size(); ++i)
{
--in[v[k][i]];
if (minn[v[k][i]]>minn[k]+timp[k]) minn[v[k][i]]=minn[k]+timp[k];
if (in[v[k][i]]==0) q.push(v[k][i]);
}
}
}
int main ()
{
f>>n;
for (i=1; i<=n; ++i)
f>>timp[i];
for (i=1; i<=n; ++i)
{
f>>k; minn[i]=inf;
for (j=1; j<=k; ++j)
{
f>>var; ++in[i]; ++out[var];
v[var].push_back(i);
}
}
for (i=1; i<=n; ++i)
if (in[i]==0) q.push(i), minn[i]=0;
BF ();
g<<VV<<"\n";
for (i=1; i<=n; ++i)
g<<minn[i]<<" "<<maxx[i]<<"\n";
return 0;
}