답안 #702051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702051 2023-02-22T14:16:38 Z huomark1001 Olympic Bus (JOI20_ho_t4) C++17
0 / 100
27 ms 4000 KB
#include<bits/stdc++.h>
#include<random>
using namespace std;

template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);

#define float double
#define ss(n) fixed<<setprecision(n) 
#define ll long long
#define int ll
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define rep(i,a) for(int i=1;i<=a;i++)
#define rep0(i,a) for(int i=0;i<a;i++)
#define F first
#define S second
#define uni(a) a.resize(distance(a.begin(),unique(a.begin(),a.end())));
#define unisort(a) sort(a.begin(),a.end()); uni(a);

ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}

const ld pi=3.14159265358979323846264338327950288419716939931;
const int lar=3e18;
const int mol1=1e9+7;
const int mol2=998244353;
const int MX=3e5;

vector<int>node[205];
int dis[205][205];
void solve()
{
    int n,m;
    cin>>n>>m;
    rep(i,n){
        rep(j,n){
            if(i==j) dis[i][j]=0;
            else dis[i][j]=lar;
        }
    }
    int u[m+1],v[m+1],c[m+1],d[m+1];
    rep(i,m){
        cin>>u[i]>>v[i]>>c[i]>>d[i];
        node[u[i]].pb(v[i]);
        dis[u[i]][v[i]]=min(dis[u[i]][v[i]],c[i]);
    }
    rep(i,n){
        rep(j,n){
            if(i==j) continue;
            rep(k,n){
                if(k==j) continue;
                dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
            }
        }
    }
    int ans=dis[1][n]+dis[n][1];
    rep(i,m){
        int x=u[i],y=v[i];
        int pp=dis[x][y];
        dis[x][y]=lar;
        ans=min({ans,dis[1][n]+dis[n][1],dis[1][n]+dis[n][y]+c[i]+d[i]+dis[x][1],dis[1][y]+c[i]+d[i]+dis[x][n]+dis[n][1]});
        ans=min(ans,dis[1][y]+c[i]+c[i]+d[i]+dis[x][n]+dis[n][y]+dis[x][1]);
        dis[x][y]=pp;
    }
    if(ans>=lar) cout<<-1<<"\n";
    else cout<<ans<<"\n";
}           

signed main()
{
    IO
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 596 KB Output is correct
2 Incorrect 12 ms 664 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3820 KB Output is correct
2 Correct 25 ms 3800 KB Output is correct
3 Correct 27 ms 4000 KB Output is correct
4 Correct 10 ms 756 KB Output is correct
5 Correct 12 ms 724 KB Output is correct
6 Incorrect 10 ms 596 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 720 KB Output is correct
2 Incorrect 10 ms 668 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 596 KB Output is correct
2 Incorrect 12 ms 664 KB Output isn't correct
3 Halted 0 ms 0 KB -