답안 #535329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535329 2022-03-10T03:07:05 Z Biaz Olympic Bus (JOI20_ho_t4) C++17
5 / 100
1000 ms 3660 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define fi first
#define se second
#define ist insert
using namespace std;
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
typedef long long ll;
typedef pair<ll,ll> pii;
const int N=205;
const int MOD=1000000007;//998244353
const int INF=1700000000000000000;//2147483647;

int n,m;
struct I{
    int u,v,c,D,id;
} ee[50005];

vector<pii> e[N];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int d[N];
int dij(int s,int t){
    memset(d,0x3f,sizeof(d));
    d[s]=0;
    pq.push({0,s});
    while (pq.size()){
        int v=pq.top().se,w=pq.top().fi;pq.pop();
        if (d[v]<w) continue;
        for (pii i:e[v]) if(d[i.fi]>w+i.se){
            d[i.fi]=w+i.se;
            pq.push({d[i.fi],i.fi});
        }
    }
    return d[t];
}
inline void sol(){
    cin >>n>>m;
    for (int i=0;i<m;i++){
        cin >>ee[i].u>>ee[i].v>>ee[i].c>>ee[i].D;
    }
    int ans=INF;
    for (int kk=0;kk<=m;kk++){
        for (int i=1;i<=n;i++) e[i].clear();
        int cst=0;
        for (int i=0;i<m;i++){
            if (i==kk) e[ee[i].v].pb({ee[i].u,ee[i].c}),cst=ee[i].D;
            else e[ee[i].u].pb({ee[i].v,ee[i].c});
        }
        ans=min(ans,dij(1,n)+dij(n,1)+cst);
    }
    cout <<(ans==INF?-1:ans)<<'\n';
}
signed main(){
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 48 ms 340 KB Output is correct
4 Correct 51 ms 400 KB Output is correct
5 Correct 19 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 13 ms 408 KB Output is correct
10 Correct 70 ms 388 KB Output is correct
11 Correct 68 ms 408 KB Output is correct
12 Correct 79 ms 400 KB Output is correct
13 Correct 31 ms 324 KB Output is correct
14 Correct 35 ms 412 KB Output is correct
15 Correct 32 ms 392 KB Output is correct
16 Correct 34 ms 388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 3660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 340 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Execution timed out 1080 ms 3388 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 48 ms 340 KB Output is correct
4 Correct 51 ms 400 KB Output is correct
5 Correct 19 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 13 ms 408 KB Output is correct
10 Correct 70 ms 388 KB Output is correct
11 Correct 68 ms 408 KB Output is correct
12 Correct 79 ms 400 KB Output is correct
13 Correct 31 ms 324 KB Output is correct
14 Correct 35 ms 412 KB Output is correct
15 Correct 32 ms 392 KB Output is correct
16 Correct 34 ms 388 KB Output is correct
17 Execution timed out 1086 ms 3660 KB Time limit exceeded
18 Halted 0 ms 0 KB -