JZOI1134 迷宫(maze)

#include <bits/stdc++.h>
#define ll long long
#define INF 2147483647
#define mem_INF 2139062143
#define ll_INF 9223372036854775807
#define eps 1e-8
#define fuckrand() ( ( rand() << 15 ) ^ rand() )
using namespace std;
inline int read() {
    int x = 0,tmp = 1;char ch = getchar();
    while( ch < '0' || ch > '9' ) {if ( ch == '-' ) tmp = -1; ch = getchar();}
    while( ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar(); }
    return x * tmp;
}
struct Node {
    int to, next, t, w;
} edge[21000];
bool used[11000];
int N, M, __t__, v;
int head[110], idx = 0, ans_t = __t__, ans_w = 0;
inline void ade( int u, int v, int t, int w ) {
    edge[++ idx].to = v;
    edge[idx].w = w;
    edge[idx].t = t;
    edge[idx].next = head[u];
    head[u] = idx;
}
inline void add( int u, int v, int t, int w ) {
    ade( u, v, t, w );
    ade( v, u, t, w );
}
void dfs( int now, int t, int w ) {
    if( t > __t__ || w > v ) return;
    else if( now == N ) {
        if( w < ans_w ) return;
         
        if( w > ans_w ) {
            ans_w = w;
            ans_t = t;
        } else if( w == ans_w ) ans_t = min( t, ans_t ); 
        return;
    } else {
        for( int i = head[now] ; i != -1 ; i = edge[i].next ) if( !used[( i + 1 ) >> 1] ){
            int son = edge[i].to, _t = edge[i].t, _w = edge[i].w;
            used[( i + 1 ) >> 1] = 1;
            dfs( son, t + _t, w + _w );
            used[( i + 1 ) >> 1] = 0;
        }
    }
}
int main() {
    memset( head, -1, sizeof( head ) );
    memset( used, 0, sizeof( used ) );
    N = read(), M = read(), __t__ = read(), v = read();
    for( int i = 1 ; i <= M ; ++ i ) {
        int u = read(), v = read(), t = read(), w = read();
        ade( u, v, t, w );
        ade( v, u, t, w );
    }
    dfs( 1, 0, 0 );
    printf( "%d %d\n", ans_t, v - ans_w );
 
    return 0;
}
--数据点-----N------Q---max{A_x}
13310
2101010000
3101010000
4101000010000
52610000100000000
62610000100000000
726100001000000000000
8261000010000000000000000
9265000010000000000000000
102610000010000000000000000

转载于:https://www.cnblogs.com/ARZhu-NOIpAK/p/6696277.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值