#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define ALL(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2e5+5,inf = 0x3f3f3f3f;
struct edge{int v,r,p;};
int n,m,l[N],r[N];
vector <edge> G[N];
bool vis[N];
bool dfs(int u,int x){
if(x <= l[u])return 0;
if(x >= r[u])return 1;
vis[u] = 1;
for(auto &t:G[u]){
if(x >= t.r){
if(vis[t.v]){
vis[u] = 0,r[u] = x;
return 1;
}
if(dfs(t.v,min(inf,x + t.p))){
vis[u] = 0,r[u] = x;
return 1;
}
}
}
vis[u] = 0,l[u] = x;
return 0;
}
int main(){
n = read(),m = read();
rep(i,1,m){
int a = read(),b = read(),r = read(),p = read();
G[a].pb((edge){b,r,p});
}
rep(i,1,n)l[i] = -1,r[i] = inf + 1;
rep(i,1,n){
int L = 0,R = inf;
while(L < R){
int mid = (L + R) >> 1;
if(dfs(i,mid))R = mid;
else L = mid+1;
}
if(L == inf)printf("-1%c"," \n"[i==n]);
else printf("%d%c",L," \n"[i==n]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
4 ms |
5112 KB |
Output is correct |
3 |
Correct |
3 ms |
5020 KB |
Output is correct |
4 |
Correct |
5 ms |
5060 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
3 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5196 KB |
Output is correct |
9 |
Correct |
5 ms |
5124 KB |
Output is correct |
10 |
Correct |
3 ms |
5016 KB |
Output is correct |
11 |
Correct |
4 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
3 ms |
5044 KB |
Output is correct |
14 |
Correct |
5 ms |
5280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
12636 KB |
Output is correct |
2 |
Correct |
152 ms |
12688 KB |
Output is correct |
3 |
Correct |
28 ms |
9872 KB |
Output is correct |
4 |
Correct |
47 ms |
7688 KB |
Output is correct |
5 |
Correct |
126 ms |
12068 KB |
Output is correct |
6 |
Correct |
114 ms |
11976 KB |
Output is correct |
7 |
Correct |
33 ms |
9180 KB |
Output is correct |
8 |
Correct |
1194 ms |
28332 KB |
Output is correct |
9 |
Correct |
256 ms |
14532 KB |
Output is correct |
10 |
Correct |
32 ms |
8520 KB |
Output is correct |
11 |
Correct |
110 ms |
11396 KB |
Output is correct |
12 |
Correct |
15 ms |
9276 KB |
Output is correct |
13 |
Correct |
13 ms |
8308 KB |
Output is correct |
14 |
Correct |
1162 ms |
28360 KB |
Output is correct |
15 |
Correct |
1177 ms |
28384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
4 ms |
5112 KB |
Output is correct |
3 |
Correct |
3 ms |
5020 KB |
Output is correct |
4 |
Correct |
5 ms |
5060 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
3 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5196 KB |
Output is correct |
9 |
Correct |
5 ms |
5124 KB |
Output is correct |
10 |
Correct |
3 ms |
5016 KB |
Output is correct |
11 |
Correct |
4 ms |
5068 KB |
Output is correct |
12 |
Correct |
3 ms |
5068 KB |
Output is correct |
13 |
Correct |
3 ms |
5044 KB |
Output is correct |
14 |
Correct |
5 ms |
5280 KB |
Output is correct |
15 |
Correct |
188 ms |
12636 KB |
Output is correct |
16 |
Correct |
152 ms |
12688 KB |
Output is correct |
17 |
Correct |
28 ms |
9872 KB |
Output is correct |
18 |
Correct |
47 ms |
7688 KB |
Output is correct |
19 |
Correct |
126 ms |
12068 KB |
Output is correct |
20 |
Correct |
114 ms |
11976 KB |
Output is correct |
21 |
Correct |
33 ms |
9180 KB |
Output is correct |
22 |
Correct |
1194 ms |
28332 KB |
Output is correct |
23 |
Correct |
256 ms |
14532 KB |
Output is correct |
24 |
Correct |
32 ms |
8520 KB |
Output is correct |
25 |
Correct |
110 ms |
11396 KB |
Output is correct |
26 |
Correct |
15 ms |
9276 KB |
Output is correct |
27 |
Correct |
13 ms |
8308 KB |
Output is correct |
28 |
Correct |
1162 ms |
28360 KB |
Output is correct |
29 |
Correct |
1177 ms |
28384 KB |
Output is correct |
30 |
Correct |
157 ms |
16608 KB |
Output is correct |
31 |
Correct |
171 ms |
16588 KB |
Output is correct |
32 |
Correct |
18 ms |
11532 KB |
Output is correct |
33 |
Correct |
46 ms |
7700 KB |
Output is correct |
34 |
Correct |
109 ms |
15748 KB |
Output is correct |
35 |
Correct |
139 ms |
15820 KB |
Output is correct |
36 |
Correct |
29 ms |
12180 KB |
Output is correct |
37 |
Correct |
1160 ms |
32288 KB |
Output is correct |
38 |
Correct |
208 ms |
18820 KB |
Output is correct |
39 |
Correct |
23 ms |
10676 KB |
Output is correct |
40 |
Correct |
132 ms |
14228 KB |
Output is correct |
41 |
Correct |
15 ms |
10500 KB |
Output is correct |
42 |
Correct |
15 ms |
9172 KB |
Output is correct |
43 |
Correct |
1104 ms |
32424 KB |
Output is correct |
44 |
Correct |
1124 ms |
32280 KB |
Output is correct |
45 |
Correct |
1044 ms |
32320 KB |
Output is correct |
46 |
Correct |
1084 ms |
19676 KB |
Output is correct |
47 |
Correct |
421 ms |
16196 KB |
Output is correct |
48 |
Correct |
95 ms |
14708 KB |
Output is correct |
49 |
Correct |
358 ms |
19380 KB |
Output is correct |
50 |
Correct |
3 ms |
4988 KB |
Output is correct |