#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
int sz(const T &a){return int(a.size());}
const int MN=2e5+1;
int outdeg[MN];
vector<pair<pii,pii>> in[MN];
bool pruned[MN];
int te[MN],val[MN];
bool done[MN];
void pruneedge(const pair<pair<pii,pii>,int> &teedge){
if(done[teedge.second])return;
done[teedge.second]=true;
pair<pii,pii> edge=teedge.first;
te[edge.first.first]=min(te[edge.first.first],max(edge.second.first,val[edge.first.second]-edge.second.second));
outdeg[edge.first.first]--;
if(outdeg[edge.first.first]==0){
val[edge.first.first]=te[edge.first.first];
pruned[edge.first.first]=true;
for(auto x:in[edge.first.first]){
pruneedge({{{x.first.first,edge.first.first},x.second},x.first.second});
}
}
}
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n,m,a,b,c,d;
cin>>n>>m;
vector<pair<pair<pii,pii>,int>> edges;
for(int i=0;i<m;i++){
cin>>a>>b>>c>>d;
edges.push_back({{{a,b},{c,d}},i});
outdeg[a]++;
in[b].push_back({{a,i},{c,d}});
}
queue<int> prun;
for(int i=1;i<=n;i++){
te[i]=INT_MAX;
if(outdeg[i]==0)prun.push(i);
}
while(sz(prun)){
int cur=prun.front();
prun.pop();
pruned[cur]=true;
for(auto x:in[cur]){
outdeg[x.first.first]--;
if(outdeg[x.first.first]==0){
prun.push(x.first.first);
}
}
}
sort(edges.begin(),edges.end(),[&](const auto &lhs, const auto &rhs){
return lhs.first.second.first>rhs.first.second.first;
});
for(auto x:edges){
if(!pruned[x.first.first.second]){
pruneedge(x);
}
}
for(int i=1;i<=n;i++){
if(te[i]==INT_MAX)printf("-1%c"," \n"[i==n]);
else printf("%d%c",val[i]," \n"[i==n]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5068 KB |
Output is correct |
2 |
Correct |
5 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5068 KB |
Output is correct |
4 |
Correct |
5 ms |
5068 KB |
Output is correct |
5 |
Correct |
5 ms |
5060 KB |
Output is correct |
6 |
Correct |
5 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
5 ms |
5324 KB |
Output is correct |
9 |
Correct |
5 ms |
5068 KB |
Output is correct |
10 |
Correct |
4 ms |
5068 KB |
Output is correct |
11 |
Correct |
5 ms |
5068 KB |
Output is correct |
12 |
Correct |
4 ms |
5068 KB |
Output is correct |
13 |
Correct |
4 ms |
5152 KB |
Output is correct |
14 |
Correct |
5 ms |
5324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
186 ms |
17836 KB |
Output is correct |
2 |
Correct |
201 ms |
17920 KB |
Output is correct |
3 |
Correct |
112 ms |
14368 KB |
Output is correct |
4 |
Correct |
27 ms |
9512 KB |
Output is correct |
5 |
Correct |
191 ms |
16452 KB |
Output is correct |
6 |
Correct |
170 ms |
16488 KB |
Output is correct |
7 |
Correct |
113 ms |
13800 KB |
Output is correct |
8 |
Correct |
245 ms |
35524 KB |
Output is correct |
9 |
Correct |
200 ms |
19260 KB |
Output is correct |
10 |
Correct |
103 ms |
13908 KB |
Output is correct |
11 |
Correct |
157 ms |
16220 KB |
Output is correct |
12 |
Correct |
96 ms |
13924 KB |
Output is correct |
13 |
Correct |
83 ms |
13304 KB |
Output is correct |
14 |
Correct |
232 ms |
35572 KB |
Output is correct |
15 |
Correct |
244 ms |
35540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5068 KB |
Output is correct |
2 |
Correct |
5 ms |
5068 KB |
Output is correct |
3 |
Correct |
4 ms |
5068 KB |
Output is correct |
4 |
Correct |
5 ms |
5068 KB |
Output is correct |
5 |
Correct |
5 ms |
5060 KB |
Output is correct |
6 |
Correct |
5 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
5 ms |
5324 KB |
Output is correct |
9 |
Correct |
5 ms |
5068 KB |
Output is correct |
10 |
Correct |
4 ms |
5068 KB |
Output is correct |
11 |
Correct |
5 ms |
5068 KB |
Output is correct |
12 |
Correct |
4 ms |
5068 KB |
Output is correct |
13 |
Correct |
4 ms |
5152 KB |
Output is correct |
14 |
Correct |
5 ms |
5324 KB |
Output is correct |
15 |
Correct |
186 ms |
17836 KB |
Output is correct |
16 |
Correct |
201 ms |
17920 KB |
Output is correct |
17 |
Correct |
112 ms |
14368 KB |
Output is correct |
18 |
Correct |
27 ms |
9512 KB |
Output is correct |
19 |
Correct |
191 ms |
16452 KB |
Output is correct |
20 |
Correct |
170 ms |
16488 KB |
Output is correct |
21 |
Correct |
113 ms |
13800 KB |
Output is correct |
22 |
Correct |
245 ms |
35524 KB |
Output is correct |
23 |
Correct |
200 ms |
19260 KB |
Output is correct |
24 |
Correct |
103 ms |
13908 KB |
Output is correct |
25 |
Correct |
157 ms |
16220 KB |
Output is correct |
26 |
Correct |
96 ms |
13924 KB |
Output is correct |
27 |
Correct |
83 ms |
13304 KB |
Output is correct |
28 |
Correct |
232 ms |
35572 KB |
Output is correct |
29 |
Correct |
244 ms |
35540 KB |
Output is correct |
30 |
Correct |
189 ms |
17864 KB |
Output is correct |
31 |
Correct |
197 ms |
17804 KB |
Output is correct |
32 |
Correct |
105 ms |
14408 KB |
Output is correct |
33 |
Correct |
27 ms |
9360 KB |
Output is correct |
34 |
Correct |
166 ms |
16436 KB |
Output is correct |
35 |
Correct |
176 ms |
16456 KB |
Output is correct |
36 |
Correct |
120 ms |
13804 KB |
Output is correct |
37 |
Correct |
233 ms |
35536 KB |
Output is correct |
38 |
Correct |
222 ms |
18736 KB |
Output is correct |
39 |
Correct |
103 ms |
14076 KB |
Output is correct |
40 |
Correct |
190 ms |
16196 KB |
Output is correct |
41 |
Correct |
110 ms |
13732 KB |
Output is correct |
42 |
Correct |
91 ms |
13984 KB |
Output is correct |
43 |
Correct |
240 ms |
35544 KB |
Output is correct |
44 |
Correct |
240 ms |
35528 KB |
Output is correct |
45 |
Correct |
234 ms |
35588 KB |
Output is correct |
46 |
Correct |
148 ms |
20956 KB |
Output is correct |
47 |
Correct |
160 ms |
24268 KB |
Output is correct |
48 |
Correct |
180 ms |
24388 KB |
Output is correct |
49 |
Correct |
191 ms |
24444 KB |
Output is correct |
50 |
Correct |
4 ms |
4940 KB |
Output is correct |