#include <bits/stdc++.h>
#define MAXN 107
#define MAXK 1007
using namespace std;
long long bp[MAXN][MAXK],sp[MAXN][MAXK],d[MAXN][MAXN],w[MAXN][MAXN],wb[MAXN][MAXN],dist[MAXN],dn[MAXN];
int n,m,a;
void zvonocovek()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) if(i!=j && wb[i][j]!=n-2)
dist[j]=min(dist[j],dist[i]+wb[i][j]);
}
bool provera(long long k)
{
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)
{
if(1000000000000000LL/k>d[i][j]) wb[i][j]=n-2;
wb[i][j]=n*(d[i][j]*k-w[i][j])-1;
}
dist[1]=0;
for(int i=2;i<=n;i++) dist[i]=1000000000000000000LL;
for(int i=1;i<=n;i++) zvonocovek();
for(int i=1;i<=n;i++) dn[i]=dist[i];
zvonocovek();
for(int i=1;i<=n;i++) if(dist[i]!=dn[i]) return true;
return false;
}
long long binarna(long long l, long long r)
{
if(l==r) return l;
long long s=(l+r+1)/2;
if(provera(s)) return binarna(s,r);
return binarna(l,s-1);
}
int main()
{
cin>>n>>m>>a;
for(int i=1;i<=n;i++) for(int j=1;j<=a;j++) cin>>bp[i][j]>>sp[i][j];
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=1000000000000000000LL;
for(int i=1;i<=m;i++)
{
int t1,t2; long long t3;
cin>>t1>>t2>>t3;
d[t1][t2]=min(d[t1][t2],t3);
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) if(i!=j)
for(int k=1;k<=a;k++) if(bp[i][k]!=-1 && sp[j][k]!=-1)
w[i][j]=max(w[i][j],sp[j][k]-bp[i][k]);
//for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) printf("%d %d %lld %lld\n",i,j,d[i][j],w[i][j]);
printf("%d",binarna(0,2000000000));
}
Compilation message
merchant.cpp: In function 'int main()':
merchant.cpp:55:35: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
printf("%d",binarna(0,2000000000));
~~~~~~~~~~~~~~~~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
2020 KB |
Output is correct |
2 |
Incorrect |
47 ms |
1272 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
888 KB |
Output is correct |
2 |
Correct |
9 ms |
888 KB |
Output is correct |
3 |
Correct |
10 ms |
888 KB |
Output is correct |
4 |
Correct |
9 ms |
888 KB |
Output is correct |
5 |
Correct |
13 ms |
888 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
9 ms |
888 KB |
Output is correct |
8 |
Correct |
10 ms |
888 KB |
Output is correct |
9 |
Correct |
9 ms |
888 KB |
Output is correct |
10 |
Correct |
10 ms |
888 KB |
Output is correct |
11 |
Correct |
13 ms |
928 KB |
Output is correct |
12 |
Correct |
13 ms |
888 KB |
Output is correct |
13 |
Correct |
11 ms |
888 KB |
Output is correct |
14 |
Correct |
11 ms |
888 KB |
Output is correct |
15 |
Correct |
15 ms |
888 KB |
Output is correct |
16 |
Correct |
9 ms |
760 KB |
Output is correct |
17 |
Correct |
12 ms |
968 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
13 ms |
892 KB |
Output is correct |
20 |
Correct |
13 ms |
892 KB |
Output is correct |
21 |
Correct |
13 ms |
888 KB |
Output is correct |
22 |
Correct |
11 ms |
888 KB |
Output is correct |
23 |
Correct |
9 ms |
888 KB |
Output is correct |
24 |
Correct |
9 ms |
888 KB |
Output is correct |
25 |
Correct |
11 ms |
888 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
9 ms |
760 KB |
Output is correct |
28 |
Correct |
9 ms |
888 KB |
Output is correct |
29 |
Correct |
9 ms |
760 KB |
Output is correct |
30 |
Correct |
2 ms |
504 KB |
Output is correct |
31 |
Correct |
11 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
1532 KB |
Output is correct |
2 |
Correct |
206 ms |
2168 KB |
Output is correct |
3 |
Correct |
56 ms |
1400 KB |
Output is correct |
4 |
Incorrect |
67 ms |
1528 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
888 KB |
Output is correct |
2 |
Correct |
9 ms |
888 KB |
Output is correct |
3 |
Correct |
10 ms |
888 KB |
Output is correct |
4 |
Correct |
9 ms |
888 KB |
Output is correct |
5 |
Correct |
13 ms |
888 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
9 ms |
888 KB |
Output is correct |
8 |
Correct |
10 ms |
888 KB |
Output is correct |
9 |
Correct |
9 ms |
888 KB |
Output is correct |
10 |
Correct |
10 ms |
888 KB |
Output is correct |
11 |
Correct |
13 ms |
928 KB |
Output is correct |
12 |
Correct |
13 ms |
888 KB |
Output is correct |
13 |
Correct |
11 ms |
888 KB |
Output is correct |
14 |
Correct |
11 ms |
888 KB |
Output is correct |
15 |
Correct |
15 ms |
888 KB |
Output is correct |
16 |
Correct |
9 ms |
760 KB |
Output is correct |
17 |
Correct |
62 ms |
1532 KB |
Output is correct |
18 |
Correct |
206 ms |
2168 KB |
Output is correct |
19 |
Correct |
56 ms |
1400 KB |
Output is correct |
20 |
Incorrect |
67 ms |
1528 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |