猫史档案馆


代码教程第三期(武器)

用户:YJH于YYDSYJH于YYDS查看:5 回复:4 评论:5 创建时间:2022-07-25T15:00:20






world.onPlayerJoin(async ({ entity }) => {//各项数据初始化
    entity.enableDamage = true//允许伤害
    entity.hp = 100

    entity.money = Infinity

    entity.bag = ['龙骨喵']
    
})



//好奇葩啊,你为什么要用entity这个名字作为介绍内容的key



var lyw = [{ name: '三叉戟', entity: '伤害:100000;冷却时间:10;' }, { name: "太空机关喵", entity: "介绍内容" }]//你这个列表中括号是不是忘加了



world.onPlayerJoin(async ({ entity }) => {//各项数据初始化
      
      if (button == Box3ButtonType.ACTION1) {//右键判定

        const selection = await entity.player.dialog({

            type: Box3DialogType.SELECT,

            content: `金币:[${entity.money}]`,

            options: entity.bag,

        })

        if (selection) {

            entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0]);

            entity.player.hand = selection.value



            if (selection.value == '三叉戟') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,//那这里呢,也不改了??

                    options: ['装上']

                })



                if (!selection || selection === null) {

                    return

                }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/三叉戟.vb',

                    orientation: new Box3Quaternion(1, 0, 1.5, -1).rotateY(Math.PI / 2),

                    scale: new Box3Vector3(0.5, 0.75, 0.5),//

                })

            } else if (selection.value == '风神喵') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/风神喵.vb',

                    orientation: new Box3Quaternion(1, 0, 1.5, -1).rotateY(Math.PI / 2),

                    scale: (0.35, 0.5, 0.35)

                })

            } else if (selection.value == '铁剑') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) { return }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/铁剑.vb',

                    orientation: new Box3Quaternion(0.4, 1, 0, 1),

                    scale: new Box3Vector3(1, 1, 1),

                    offset: new Box3Vector3(0, 0, 0.4)

                })

            } else if (selection.value == '风神剑') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/风神剑.vb',

                    orientation: new Box3Quaternion(1, 0, 1.5, -1).rotateY(Math.PI / 2),

                    scale: new Box3Vector3(0.35, 0.5, 0.35),









                })

            } else if (selection.value == '大师之剑') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/大师之剑.vb',

                    orientation: new Box3Quaternion(1, 0, 1.5, -1).rotateY(Math.PI / 2),

                    scale: new Box3Vector3(0.35, 0.5, 0.35),

                    scale: (0.3, 0.3, 0.3),

                })











            } else if (selection.value == '嗜血剑') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/嗜血剑.vb',

                    orientation: new Box3Quaternion(1, 0, 1.5, -1).rotateY(Math.PI / 2),

                    scale: new Box3Vector3(0.35, 0.5, 0.35),

                })

            } else if (selection.value == '屠龙圣剑') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/屠龙圣剑.vb',

                    orientation: new Box3Quaternion(1, 0, 1.5, -1).rotateY(Math.PI / 2),

                    scale: (0.35, 0.5, 0.35),







                })

            } else if (selection.value == '激光粒子喵') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: 'hhhh',

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/激光粒子喵.vb',

                    orientation: new Box3Quaternion(1, 0, 1.5, -1).rotateY(Math.PI / 2),

                    scale: new Box3Vector3(0.35, 0.35, 0.35),

                })







            } else if (selection.value == '代码兵王·虎年新皮') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }



                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/代码兵王·虎年新皮.vb',

                    orientation: new Box3Quaternion(0.4, 1, 0, 1).rotateY(-Math.PI / 1),

                    scale: new Box3Vector3(0.3, 0.3, 0.3),

                    offset: new Box3Vector3(0, 0, 0.6),

                })

            } else if (selection.value == '悬重尺') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }

                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/踏浪尺.vb',

                    orientation: new Box3Quaternion(0.4, 1, 0, 1).rotateZ(-Math.PI / 3),

                    scale: new Box3Vector3(0.5, 0.5, 0.5),

                    offset: new Box3Vector3(0.3, -0.09, 0.74),

                })

            } else if (selection.value == '龙骨喵') {

                const selection = await entity.player.dialog({

                    type: Box3DialogType.SELECT, //对话框类型为选择框

                    title: lyw[1].name,

                    content: lyw[1].entity,

                    options: ['装上']//反了,是lyw[1].entity,其他的也是同样

                })



                if (!selection || selection === null) {

                    return

                }

                entity.player.addWearable({

                    bodyPart: Box3BodyPart.RIGHT_HAND,

                    mesh: 'mesh/龙骨喵.vb',

                    orientation: new Box3Quaternion(0.4, 1, 0, 1).rotateZ(-Math.PI / 3),

                    scale: new Box3Vector3(1, 1, 1.),

                    offset: new Box3Vector3(0.3, -0.09, 0.74),



                })



            }

        }











    } else if (button === Box3ButtonType.ACTION0) {

        if (entity.player.hand == "激光粒子喵") {

            var ball = world.createEntity({

                mesh: 'mesh/光球.vb',

                position: entity.position,

                collides: true,

                gravity: false,

                fixed: false,

                hurt: (100),

            })

            ball.id = entity.player.userKey

            ball.onEntityContact(({ other }) => {

                other.hurt(10)//被碰实体受10点伤害

                ball.destroy()

            })

            while (!(ball.x > 200 || ball.x < 80 || ball.z > 200 || ball.z < 80)) {

                ball.position.x += direction.x;

                ball.position.y += direction.y;

                ball.position.z += direction.z;

                await sleep(10)

            }

            ball.destroy()

        } else if (button === Box3ButtonType.ACTION0) {

            if (entity.player.hand == "铁剑") {

                var ball = world.createEntity({

                    mesh: 'mesh/剑气.vb',

                    position: entity.position,



                    collides: true,

                    gravity: false,

                    fixed: false,

                    hurt: (100),

                })

                ball.id = entity.player.userKey

                ball.onEntityContact(({ other }) => {

                    other.hurt(100)//被碰实体受10点伤害

                })



                while (!(ball.x > 200 || ball.x < 80 || ball.z > 200 || ball.z < 80)) {

                    ball.position.x += direction.x;

                    ball.position.y += direction.y;

                    ball.position.z += direction.z;

                    await sleep(10)



                }



            } else if (entity.player.hand == "三叉戟") {

                var ball = world.createEntity({

                    mesh: 'mesh/剑气.vb',

                    position: entity.position,



                    collides: true,

                    gravity: false,

                    fixed: false,

                    hurt: (100),

                })

                ball.id = entity.player.userKey

                ball.onEntityContact(({ other }) => {

                    other.hurt(100)//被碰实体受10点伤害

                })



                while (!(ball.x > 200 || ball.x < 80 || ball.z > 200 || ball.z < 80)) {

                    ball.position.x += direction.x;

                    ball.position.y += direction.y;

                    ball.position.z += direction.z;

                    await sleep(10)

                }

            } else if (entity.player.hand == "代码兵王·虎年新皮") {

                var ball = world.createEntity({

                    mesh: 'mesh/技能光球.vb',



                    position: entity.position,

                    collides: true,

                    gravity: false,

                    fixed: false,

                    hurt: (100),

                })

                ball.id = entity.player.userKey

                ball.onEntityContact(({ other }) => {

                    other.hurt(喵0000)//被碰实体受10点伤害

                })



                while (!(ball.x > 200 || ball.x < 80 || ball.z > 200 || ball.z < 80)) {

                    ball.position.x += direction.x;

                    ball.position.y += direction.y;

                    ball.position.z += direction.z;

                    await sleep(10)

                }

            } else if (entity.player.hand == "悬重尺") {

                var ball = world.createEntity({

                    mesh: 'mesh/剑气.vb',



                    position: entity.position,

                    collides: true,

                    gravity: false,

                    fixed: false,

                    hurt: (100),

                })

                ball.id = entity.player.userKey

                ball.onEntityContact(({ other }) => {

                    other.hurt(100)//被碰实体受10点伤害

                })



                while (!(ball.x > 200 || ball.x < 80 || ball.z > 200 || ball.z < 80)) {

                    ball.position.x += direction.x;

                    ball.position.y += direction.y;

                    ball.position.z += direction.z;

                    await sleep(10)

                }

                world.onPress(async ({ entity, button, raycast: { direction } }) => {

                    if (button === Box3ButtonType.ACTION0) {

                        if (entity.player.hand == '龙骨喵') {

                            entity.player.gaster_blaster = true;

                            let pos = new Box3Vector3(entity.position.x, entity.position.y + 1, entity.position.z)

                            var gaster_blaster = world.createEntity({

                                mesh: '',

                                position: pos,

                                meshScale: new Box3Vector3(0.1, 0.1, 0.1),

                                meshOrientation: QUAT.rotateY(Math.atan2(direction.z, direction.x)),

                                gravity: false,

                                collides: false,

                                fixed: false

                            })

                            entity.sound({ 'sample': 'audio/gb1.mp3', 'radius': 150 })

                            gaster_blaster.position.x -= direction.x * 10;

                            gaster_blaster.position.z -= direction.z * 10;

                            gaster_blaster.mesh = 'mesh/龙骨炮.vb'

                            for (let i = 1; i <= 180; i++) {

                                gaster_blaster.meshOrientation = gaster_blaster.meshOrientation.rotateY(radian(1))

                                gaster_blaster.position.x += direction.x * 0.055;

                                gaster_blaster.position.z += direction.z * 0.055;

                                await sleep(5)

                            }

                            gaster_blaster.collides = false;

                            gaster_blaster.fixed = true;

                            await sleep(1000);

                            entity.sound({ 'sample': 'audio/gb3.mp3', 'radius': 150 })

                            var pao = world.createEntity({

                                mesh: 'mesh/单元方块.vb',

                                position: gaster_blaster.position,

                                meshScale: new Box3Vector3(0.1, 0.1, 0.1),

                                meshOrientation: QUAT.rotateY(Math.atan2(direction.z, direction.x)),

                                gravity: false,

                                collides: false,

                                fixed: false

                            })

                            pao.meshScale.y = 0.2;

                            pao.meshScale.z = 0.2;

                            pao.meshOrientation = QUAT.rotateY(Math.atan2(direction.z, direction.x))

                            while (!(gaster_blaster.position.x > 300 || gaster_blaster.position.x < -50 || gaster_blaster.position.z > 300 || gaster_blaster.position.z < -50)) {

                                gaster_blaster.position.x -= direction.x * 0.4;

                                gaster_blaster.position.z -= direction.z * 0.4;

                                pao.meshScale.x += 0.75;

                                pao.position.x -= direction.x * 0.4;

                                pao.position.z -= direction.z * 0.4;

                                attack_detection = new Box3Bounds3(pao.position.sub(pao.bounds), pao.position.add(pao.bounds))

                                await sleep(5)

                            }

                            gaster_blaster.destroy()

                            pao.destroy()

                            attack_detection = undefined;

                        } else if (entity.player.hand == '龙骨喵') {

                            let pos = new Box3Vector3(entity.position.x, entity.position.y + 20, entity.position.z)

                            var gaster_blaster = world.createEntity({

                                mesh: '',

                                position: pos,

                                meshScale: new Box3Vector3(1, 1, 1),

                                meshOrientation: QUAT.rotateY(Math.atan2(direction.z, direction.x)),

                                gravity: false,

                                collides: false,

                                fixed: false

                            })

                            entity.sound({ 'sample': 'audio/gb2.mp3', 'radius': 99999 })

                            gaster_blaster.position.x -= direction.x * 10;

                            gaster_blaster.position.z -= direction.z * 10;

                            gaster_blaster.mesh = 'mesh/killer龙骨炮.vb'

                            Object.assign(gaster_blaster, {

                                particleRate: 99,

                                particleSize: [40, 40, 40, 40, 40],

                                particleColor: [

                                    new Box3RGBColor(0, 0, 0),

                                    new Box3RGBColor(0, 0, 0),

                                    new Box3RGBColor(0, 0, 0),

                                    new Box3RGBColor(0, 0, 0),

                                    new Box3RGBColor(0, 0, 0)

                                ],

                                particleLifetime: 1,

                                particleVelocitySpread: new Box3Vector3(2, 2, 2),

                            });

                            for (let i = 1; i <= 180; i++) {

                                gaster_blaster.meshOrientation = gaster_blaster.meshOrientation.rotateY(radian(1))

                                gaster_blaster.position.x += direction.x * 0.055;

                                gaster_blaster.position.z += direction.z * 0.055;

                                await sleep(5)

                            }

                            gaster_blaster.collides = false;

                            gaster_blaster.fixed = true;

                            await sleep(3000);

                            entity.sound({ 'sample': 'audio/gb3.mp3', 'radius': 99999 })

                            var pao = world.createEntity({

                                mesh: 'mesh/killer单元方块.vb',

                                position: gaster_blaster.position,

                                meshScale: new Box3Vector3(1, 1, 1),

                                meshOrientation: QUAT.rotateY(Math.atan2(direction.z, direction.x)),

                                gravity: false,

                                collides: false,

                                fixed: false

                            })

                            pao.meshScale.y = 0.2;

                            pao.meshScale.z = 0.2;

                            pao.meshOrientation = QUAT.rotateY(Math.atan2(direction.z, direction.x))

                            entity.enableDamage = false

                            world.querySelectorAll('player').forEach((entity) => {

                                entity.player.colorLUT = resources.ls('lut')[(resources.ls('lut').length * 0.9) | 0].path;

                            })

                            while (!(gaster_blaster.position.x > 500 || gaster_blaster.position.x < -250 || gaster_blaster.position.z > 500 || gaster_blaster.position.z < -250)) {

                                gaster_blaster.position.x -= direction.x;

                                gaster_blaster.position.z -= direction.z;

                                pao.meshScale.x += 1;

                                pao.meshScale.y += 0.05;

                                pao.meshScale.z += 0.05;

                                pao.position.x -= direction.x;

                                pao.position.z -= direction.z;

                                eee = new Box3Bounds3(pao.position.sub(pao.bounds), pao.position.add(pao.bounds))

                                await sleep(5)

                            }

                            world.querySelectorAll('player').forEach((entity) => {

                                entity.player.colorLUT = resources.ls('lut')[(resources.ls('lut').length * 0.35) | 0].path;

                            })

                            entity.enableDamage = true;

                            gaster_blaster.destroy()

                            pao.destroy()

                            eee = undefined;

                        }

                    }

                })

            }

        }

    }

})





world.onTick(({ elapsedTimeMS }) => {

    world.querySelectorAll('player').forEach((entity) => {

        if (!!attack_detection) {

            if (attack_detection.intersects(new Box3Bounds3(entity.position.sub(entity.bounds), entity.position.add(entity.bounds)))) {

                entity.hurt((100 / 96) * (elapsedTimeMS / 33))

            }

        }

        if (!!eee) {

            if (eee.intersects(new Box3Bounds3(entity.position.sub(entity.bounds), entity.position.add(entity.bounds)))) {

                entity.hurt(10)

            }

        }



    })

})





console.clear()





const person = world.querySelector('#老板');

person.enableInteract = true;

person.interactRadius = 3;

person.interactHint = "装备店老板";

person.onInteract(async ({ entity, targetEntity }) => {

    if (entity.hp === 0) return;

    var orientation = new Box3Quaternion(0, 0, 0, 1).rotateY(Math.atan2(entity.position.z - targetEntity.position.z, entity.position.x - targetEntity.position.x) + Math.PI / 2);

    targetEntity.meshOrientation.copy(orientation);

    var selectShop = await entity.player.dialog({

        type: 'select',

        title: '装备店',

        content: '请选择你要购买的装备',

        options: ["大师之剑:5000", "屠龙圣剑:3000", "激光粒子喵:60", "三叉戟", '代码兵王·虎年新皮', '悬重尺']

    })

    if (!selectShop || selectShop.index == null) return;

    var returnv;

    switch (selectShop.index) {

        case 0:

            returnv = await selectReturn(entity, selectShop.value, 20);

            if (entity.bag.length < 25 && returnv == true) {

                entity.money -= 5000;

                entity.bag.push("大师之剑");

                return;

            }

            if (returnv == false) return;

            break;



        case 1:

            returnv = await selectReturn(entity, selectShop.value, 300);

            if (entity.bag.length < 25 && returnv == true) {

                entity.money -= 3000;

                entity.bag.push("屠龙圣剑");

                return;

            }

            if (returnv == false) return;

            break;



        case 2:

            returnv = await selectReturn(entity, selectShop.value, 60);

            if (entity.bag.length < 25 && returnv == true) {

                entity.money -= 60;

                entity.bag.push("激光粒子喵");

                return;

            }

            if (returnv == false) return;

            break;



        case 3:

            returnv = await selectReturn(entity, selectShop.value, 10);

            if (entity.bag.length < 10 && returnv == true) {

                entity.money -= 10;

                entity.bag.push("三叉戟");

                return;

            }

            if (returnv == false) return;

            break;

        case 4:

            returnv = await selectReturn(entity, selectShop.value, 10);

            if (entity.bag.length < 10 && returnv == true) {

                entity.money -= 10;

                entity.bag.push("代码兵王·虎年新皮");

                return;

            }

            if (returnv == false) return;

            break;

        case 5:

            returnv = await selectReturn(entity, selectShop.value, 10);

            if (entity.bag.length < 10 && returnv == true) {

                entity.money -= 10;

                entity.bag.push("悬重尺");

                return;

            }

            if (returnv == false) return;

            break;

    }

})



async function selectReturn(player, value, mon) {

    var name = value.slice(0, value.indexOf(":"));

    var select = await player.player.dialog({

        type: 'select',

        title: name,

        content: '请问是否购买' + name + '?',

        options: ["购买", "取消"]

    })

    if (!select || select.index == null) return false;

    if (select.index == 0 && player.money >= mon) {

        player.player.dialog({

            type: 'text',

            content: '购买成功~'

        })

        return true;

    }

    if (select.index == 1) {

        return false;

    }

    if (select.index == 0 && player.money < mon) {

        player.player.dialog({

            type: 'text',

            content: '你的金币不够~'

        })

        return false;

    }

}



world.onDie(async ({ entity, attacker }) => {

    if (!entity.isPlayer) { return }

    for (let i = 5; i >= 1; i--) {

        entity.player.directMessage(i + '秒后复活')

        await sleep(1000)

    }

    entity.player.forceRespawn() //满血回到出生点

})













//addWearable函数可以让玩家穿戴东西。

/*

以下是这些key值对应的东西

bodyPart:穿戴的身体部位

mesh:实体的模型

orientation:实体的旋转角度

scale:实体的大小

offset:实体的3个坐标方向上的偏移

*/

world.onPlayerJoin(({ entity }) => {

    entity.player.addWearable({

        bodyPart: Box3BodyPart.TORSO,

        mesh: 'mesh/黄喵包.vb',

        orientation: new Box3Quaternion(0, 1, 0, 0).rotateY(Math.PI / 2),

        scale: new Box3Vector3(0.5, 0.5, 0.5),

        offset: new Box3Vector3(0, 0, -0.45),

    });//

});//


回复

上一页1 页 / 共 1下一页
FML饭米粒FML饭米粒

60%~70%都是空行

点赞0


评论


AlcalaAlcala

这是我的码风

#include<bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,a喵,tune=native")
#pragma GCC diagnostic error "-std=c++14"
#define inf (1e18)
#define int long long
using namespace std;
static char buf[1000100],*p1 = buf,*p2 = buf;
#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1000000,stdin),p1 == p2) ? EOF : *p1++
inline int read(){
    register int x = 0;
    register char ch = getchar();
    while(ch < '0' || ch > '9'){
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x;
}
const int maxn = 240200;
int n,m,s,t,dep[maxn],e[maxn],gap[maxn],head[maxn],vis[maxn],cnt = 1;
struct node{
    int nxt,to,val;
}p[240200];
int q[500200],top,bon;
struct edge{
    int u;
    bool operator <(const edge &v) const{
        return dep[u] < dep[v.u];
    }
};
inline edge make(int u){
    edge a;
    a.u = u;
    return a;
}
priority_queue<edge> qe;
inline int bfs(){
    for(int i = 0;i < maxn;i++){
        dep[i] = 1e18;
    }
    q[0] = t;
    dep[t] = 0;
    int sz = 1;
    while(sz){
        int &u = q[bon++];
        sz--;
        for(int i = head[u];i;i = p[i].nxt){
            if(p[i ^ 1].val && dep[p[i].to] > dep[u] + 1){
                dep[p[i].to] = dep[u] + 1;
                q[++top] = p[i].to;
                sz++;
            }
        }
    }
    return dep[s] != inf;
}
inline void reTag(int u){
    dep[u] = inf;
    for(int i = head[u];i;i = p[i].nxt){
        if(p[i].val) dep[u] = min(dep[u],dep[p[i].to] + 1);
    }
    return;
}
inline void pushDown(int u){
    for(int i = head[u];i;i = p[i].nxt){
        if(!e[u]) return;
        if(!p[i].val || dep[p[i].to] != dep[u] - 1) continue;
        int len = min(p[i].val,e[u]);
        p[i].val -= len;
        p[i ^ 1].val += len; 
        e[u] -= len;
        e[p[i].to] += len;
        if(p[i].to != s && p[i].to != t && !vis[p[i].to]){
            vis[p[i].to] = 1;
            qe.push(make(p[i].to));
        }
    }
    return;
}
inline void hlppWork(){
    if(!bfs()){
        cout<<0;
        return;
    }
    dep[s] = n;
    for(int i = 1;i <= n;i++){
        if(dep[i] != inf) ++gap[dep[i]];
    }
    for(int i = head[s];i;i = p[i].nxt){
        if(!p[i].val || dep[p[i].to] == inf) continue;
        int len = p[i].val;
        p[i].val -= len;
        p[i ^ 1].val += len;
        e[s] -= len;
        e[p[i].to] += len;
        if(p[i].to != s && p[i].to != t && !vis[p[i].to]){
            vis[p[i].to] = 1;
            qe.push(make(p[i].to));
        }
    }
    while(qe.size()){
        int u = qe.top().u;
        qe.pop();
        vis[u] = 0;
        pushDown(u);
        if(!e[u]) continue;
        if(!--gap[dep[u]]){
            for(int i = 1;i <= n;i++){
                if(i != s && i != t && dep[i] > dep[u] && dep[i] < n + 1){
                    dep[i] = n + 1;
                }
            }
        }
        reTag(u);
        gap[dep[u]]++;
        vis[u] = 1;
        qe.push(make(u));
    }
    cout<<e[t];
    return;
}
inline void add(int u,int v,int w){
    p[++cnt].nxt = head[u];
    p[cnt].to = v;
    p[cnt].val = w;
    head[u] = cnt;
    return;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    n = read();
    m = read();
    s = read();
    t = read();
    for(int i = 1;i <= m;i++){
        int u = read(),v = read(),w = read();
        add(u,v,w);
        add(v,u,0);
    }
    hlppWork();
    return 0;
}

点赞0


评论


YLG_個YLG_個

()

点赞1


评论


屑怪盗屑怪盗

保存

 

点赞0


评论