QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355679 | #4370. Road Times | Crysfly | RE | 2ms | 4144kb | C++17 | 4.5kb | 2024-03-17 02:01:16 | 2024-03-17 02:01:17 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
const ll P=2305843009213693951;
inline ll mul(ll x,ll y){
// return (__int128)x*y%P;
ll s=x*y-(ll)((long double)x*y/P)*P;
if(s<0)return s+P;
return (s<P?s:s-P);
}
//ll qpow(ll a,ll b){
// ll c=1;
// for(;b;b>>=1,a=mul(a,a))if(b&1)c=mul(c,a);
// return c;
//}
#define mod P
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=mul(x,o.x),*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 300005
#define inf 0x3f3f3f3f
int n,id[35][35],f[35][35],g[35][35],cnt;
vector<vector<double>>a;
vector<double>aa;
namespace S{
#define N 105
typedef double db;
int n,m,id[N];
db a[N][N],res[N],eps=1e-10;
inline int sgn(db x){return x>=-eps&&x<=eps?0:(x<0?-1:1);}
void pivot(int x,int y){
swap(id[n+x],id[y]);
db d=-a[x][y];
For(i,0,n)a[x][i]/=d;
a[x][y]=-1.0/d;
For(i,0,m)
if(i!=x&&sgn(a[i][y])){
d=a[i][y]; a[i][y]=0;
For(j,0,n) a[i][j]+=a[x][j]*d;
}
}
double simplex(vector<vector<double>>aa)
{
m=aa.size()-1,n=aa[0].size()-1;
For(i,0,m)For(j,0,n)a[i][j]=aa[i][j];
For(i,1,m)For(j,1,n)a[i][j]=-a[i][j];
// cout<<"m,n "<<m<<" "<<n<<"\n";
// For(i,0,m)For(j,0,n)cout<<a[i][j]<<" \n"[j==n];
For(i,1,n+m)id[i]=i;
while(1)
{
int u=1,v=0;
For(i,1,m) if(a[i][0]<a[u][0])u=i;
if(sgn(a[u][0])>=0)break;
For(j,1,n) if(sgn(a[u][j])>0 && (!v||id[j]>id[v])) v=j;
if(!v)puts("Infeasible"),exit(0);
pivot(u,v);
}
while(1)
{
int u=0,v=1;
db mn=1e9;
For(j,1,n) if(a[0][j]>a[0][v])v=j;
if(sgn(a[0][v])<=0)break;
For(i,1,m)
if(sgn(a[i][v])<0){
db t=-a[i][0]/a[i][v];
if(sgn(t-mn)<0 || (sgn(t-mn)==0 && (!u||id[i]>id[u]))) mn=t,u=i;
}
if(!u)puts("Unbounded"),exit(0);
pivot(u,v);
}
return a[0][0];
}
}
vi p;
void path(int u,int v){
p.clear();
int dis=f[u][v];
while(u!=v){
For(i,1,n)
if(id[u][i] && g[u][i]+f[i][v]==dis){
p.pb(id[u][i]);
dis-=g[u][i];
u=i; break;
}
}
}
signed main()
{
n=read();
For(i,1,n)For(j,1,n){
f[i][j]=read();
if(f[i][j]==-1)f[i][j]=inf;
else if(f[i][j])id[i][j]=++cnt;
g[i][j]=f[i][j];
}
For(k,1,n)For(i,1,n)For(j,1,n)f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
For(i,1,n)For(j,1,n)if(id[i][j]){
vector<double>t(cnt+1,0);
t[0]=g[i][j]*2,t[id[i][j]]=1;
a.pb(t);
t[0]=-g[i][j],t[id[i][j]]=-1;
a.pb(t);
}
int m=read();
For(_,1,m){
int u=read(),v=read(),w=read();
++u,++v;
path(u,v);
for(int i:{1,-1}){
vector<double>t(cnt+1,0);
for(auto x:p) t[x]=i;
t[0]=w*i;
a.pb(t);
}
}
m=read();
For(_,1,m){
int u=read(),v=read();
++u,++v;
path(u,v);
cout<<u-1<<" "<<v-1;
for(int i:{-1,1}){
vector<double>t(cnt+1,0);
for(auto x:p) t[x]=i;
auto aa=a;
aa.insert(aa.begin(),t);
printf(" %.10lf",S::simplex(aa)*i);
}
cout<<"\n";
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3768kb
input:
3 0 50 -1 55 0 40 -1 40 0 1 0 2 120 3 0 1 1 2 1 0
output:
0 1 50.0000000000 80.0000000000 1 2 40.0000000000 70.0000000000 1 0 55.0000000000 110.0000000000
result:
ok 12 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
3 0 50 -1 55 0 40 -1 40 0 1 0 2 90 3 0 1 1 2 1 0
output:
0 1 50.0000000000 50.0000000000 1 2 40.0000000000 40.0000000000 1 0 55.0000000000 110.0000000000
result:
ok 12 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
3 0 50 -1 55 0 40 -1 40 0 1 0 2 180 3 0 1 1 2 1 0
output:
0 1 100.0000000000 100.0000000000 1 2 80.0000000000 80.0000000000 1 0 55.0000000000 110.0000000000
result:
ok 12 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 4048kb
input:
6 0 960 -1 -1 -1 -1 -1 0 -1 -1 1000 -1 -1 1000 0 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 1000 0 970 -1 -1 -1 -1 -1 0 3 0 3 5900 2 3 5800 2 5 5700 6 0 1 2 1 1 4 4 3 4 5 0 5
output:
0 1 1900.0000000000 1920.0000000000 2 1 1800.0000000000 1820.0000000000 1 4 1980.0000000000 2000.0000000000 4 3 1980.0000000000 2000.0000000000 4 5 1880.0000000000 1900.0000000000 0 5 5800.0000000000 5800.0000000000
result:
ok 24 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 4052kb
input:
6 0 960 -1 -1 -1 -1 -1 0 -1 -1 1000 -1 -1 1000 0 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 1000 0 940 -1 -1 -1 -1 -1 0 3 0 3 5900 2 3 5800 2 5 5700 6 0 1 2 1 1 4 4 3 4 5 0 5
output:
0 1 1920.0000000000 1920.0000000000 2 1 1820.0000000000 1820.0000000000 1 4 2000.0000000000 2000.0000000000 4 3 1980.0000000000 1980.0000000000 4 5 1880.0000000000 1880.0000000000 0 5 5800.0000000000 5800.0000000000
result:
ok 24 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
6 0 950 -1 -1 -1 -1 -1 0 -1 -1 1000 -1 -1 1000 0 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 1000 0 970 -1 -1 -1 -1 -1 0 3 0 3 5900 2 3 5800 2 5 5700 6 0 1 2 1 1 4 4 3 4 5 0 5
output:
0 1 1900.0000000000 1900.0000000000 2 1 1800.0000000000 1800.0000000000 1 4 2000.0000000000 2000.0000000000 4 3 2000.0000000000 2000.0000000000 4 5 1900.0000000000 1900.0000000000 0 5 5800.0000000000 5800.0000000000
result:
ok 24 numbers
Test #7:
score: 0
Accepted
time: 2ms
memory: 3944kb
input:
10 0 123 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 234 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 345 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 456 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 567 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 678 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 890 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 901 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 555 666 -1 -1 -1 -1 -1 -1 -1 -1...
output:
0 0 -0.0000000000 0.0000000000 0 1 216.0000000000 246.0000000000 0 2 450.0000000000 714.0000000000 0 3 1084.0000000000 1114.0000000000 0 4 1540.0000000000 1570.0000000000 0 5 2674.0000000000 2704.0000000000 0 6 3408.0000000000 3438.0000000000 0 7 4298.0000000000 4358.0000000000 0 8 5199.0000000000 5...
result:
ok 400 numbers
Test #8:
score: 0
Accepted
time: 2ms
memory: 4144kb
input:
10 0 123 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 234 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 345 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 456 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 567 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 678 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 890 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 901 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 555 666 -1 -1 -1 -1 -1 -1 -1 -1...
output:
0 0 -0.0000000000 0.0000000000 0 1 216.0000000000 246.0000000000 0 2 580.0000000000 640.0000000000 0 3 1084.0000000000 1114.0000000000 0 4 1540.0000000000 1570.0000000000 0 5 2674.0000000000 2704.0000000000 0 6 3408.0000000000 3438.0000000000 0 7 4298.0000000000 4358.0000000000 0 8 5199.0000000000 5...
result:
ok 400 numbers
Test #9:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
10 0 123 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 234 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 345 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 456 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 567 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 678 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 890 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 901 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 555 666 -1 -1 -1 -1 -1 -1 -1 -1...
output:
0 0 -0.0000000000 0.0000000000 0 1 245.0000000000 246.0000000000 0 2 609.0000000000 640.0000000000 0 3 1084.0000000000 1114.0000000000 0 4 1569.0000000000 1570.0000000000 0 5 2703.0000000000 2704.0000000000 0 6 3437.0000000000 3438.0000000000 0 7 4327.0000000000 4358.0000000000 0 8 5228.0000000000 5...
result:
ok 400 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
3 0 10 -1 -1 0 10 10 -1 0 3 0 2 21 1 0 21 2 1 21 3 0 1 1 2 2 0
output:
0 1 10.5000000000 10.5000000000 1 2 10.5000000000 10.5000000000 2 0 10.5000000000 10.5000000000
result:
ok 12 numbers
Test #11:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
8 0 10 -1 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 -1 0 10 10 -1 -1 -1 -1 -1 -1 0 8 0 7 71 1 0 71 2 1 71 3 2 71 4 3 71 5 4 71 6 5 71 7 6 71 8 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 0
output:
0 1 10.1428571429 10.1428571429 1 2 10.1428571429 10.1428571429 2 3 10.1428571429 10.1428571429 3 4 10.1428571429 10.1428571429 4 5 10.1428571429 10.1428571429 5 6 10.1428571429 10.1428571429 6 7 10.1428571429 10.1428571429 7 0 10.1428571429 10.1428571429
result:
ok 32 numbers
Test #12:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
7 0 10 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 0 10 -1 -1 -1 -1 -1 -1 0 10 10 -1 -1 -1 -1 -1 0 6 0 4 41 1 5 41 2 6 41 3 0 41 5 2 41 6 3 41 7 0 1 1 2 2 3 3 4 4 5 5 6 6 0
output:
0 1 10.0000000000 11.0000000000 1 2 10.0000000000 10.3333333333 2 3 10.0000000000 10.3333333333 3 4 10.0000000000 10.3333333333 4 5 10.0000000000 11.0000000000 5 6 10.0000000000 10.3333333333 6 0 10.0000000000 10.3333333333
result:
ok 28 numbers
Test #13:
score: -100
Runtime Error
input:
30 0 392 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 793 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 750 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 703 -1 -1 0 -1 -1 -1 -1 -1 ...