How far away ?(DFS)

本文探讨了在特定乡村环境中,如何通过唯一简单路径解决从一个房屋到另一个房屋的距离查询问题,包括输入案例解析和输出样例展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How far away ?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5766    Accepted Submission(s): 2166



Problem Description
There are n houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this "How far is it if I want to go from house A to house B"? Usually it hard to answer. But luckily int this village the answer is always unique, since the roads are built in the way that there is a unique simple path("simple" means you can't visit a place twice) between every two houses. Yout task is to answer all these curious people.
 

Input
First line is a single integer T(T<=10), indicating the number of test cases.
  For each test case,in the first line there are two numbers n(2<=n<=40000) and m (1<=m<=200),the number of houses and the number of queries. The following n-1 lines each consisting three numbers i,j,k, separated bu a single space, meaning that there is a road connecting house i and house j,with length k(0<k<=40000).The houses are labeled from 1 to n.
  Next m lines each has distinct integers i and j, you areato answer the distance between house i and house j.
 

Output
For each test case,output m lines. Each line represents the answer of the query. Output a bland line after each test case.
 

Sample Input
  
2 3 2 1 2 10 3 1 15 1 2 2 3 2 2 1 2 100 1 2 2 1
 

Sample Output
  
10 25 100 100
 

Source
ECJTU 2009 Spring Contest

AC代码:
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

const int M = 4 * 1e4 + 100;
typedef long long ll;
typedef pair<int,int> P;
vector<P>G[M];
int vis[M],isGO,e;

void dfs(int x, int cost)
{
    if(isGO || vis[x]) return ;
    if(x == e)//数据太大,要改成全局变量
    {
        isGO = 1;
        printf("%d\n",cost);
        return ;
    }
    vis[x] = 1;
    for(int i = 0; i < G[x].size(); i++)
    {
        P a = G[x][i];
        dfs(a.first,cost + a.second);
    }
    vis[x] = 0;
}

void solve()
{
    int x,y,c,n,m;
    scanf("%d %d",&n,&m);
    for(int i = 1; i < n; i++)
    {
        scanf("%d %d %d",&x,&y,&c);
        G[x].push_back(make_pair(y,c));
        G[y].push_back(make_pair(x,c));
    }
    while(m--)
    {
        isGO = 0;
        scanf("%d %d",&x,&e);
        dfs(x,0);
    }
    for(int i = 1; i <= n; i++) G[i].clear();
}

int main()
{
    int T,cnt = 0;
    scanf("%d",&T);
    while(T--)
    {
        solve();
    }
    return 0;
}



<think>好的,用户让我用中文介绍一下"How are you?"。首先,我需要确定用户的需求是什么。他们可能是在学习英语问候语,或者想了解在不同场合下的使用方式。接下来,我得考虑如何组织信息,既全面又不冗长。 首先,我应该解释这句话的基本意思,直译是“你好吗?”,但实际作为日常问候使用。然后,需要区分英式英语和美式英语的不同习惯,比如英国人更常用"You alright?",而美国人可能直接用"How are you?"。还要提到常见的回答方式,比如简短回应或反问对方,避免文化误解。 另外,要注意使用场景,比如正式与非正式场合的不同表达方式,以及回应时的注意事项,比如不需要详细回答近况。还要提醒用户,根据对方的身份调整回答方式,避免过于随意。 最后,确保使用正确的LaTeX格式,虽然这个问题可能不需要数学公式,但如果有变量或例子的话,需要用$...$或$$...$$包裹。但在这个回答中,可能用不上,所以重点还是结构清晰的中文解释,帮助用户理解和正确使用这个问候语。</think>关于英文问候语 **"How are you?"** 的使用与含义,以下是详细介绍: ### 1. **基本含义** - **直译**:你好吗?/ 你最近怎么样? - **实际用途**:日常寒暄,类似中文的“吃了吗?”(**≠ 真正关心对方健康**) ### 2. **使用场景** | 场景类型 | 常见表达形式 | 示例 | |----------------|----------------------------------|--------------------------------| | **正式场合** | How are you? | 商务会议、初次见面 | | **非正式场合** | How's it going? / How are ya? | 朋友聊天、熟人打招呼 | | **英式特色** | You alright? / Alright? | 英国日常使用频率更高 | ### 3. **回答方式** - **简短回应**(最常见): - 👍 积极:*"Good, thanks!"* - 😐 中性:*"Not bad."* - 👎 消极:*"Could be better."*(需配合苦笑示意) - **反问礼节**(90%的情况需执行): ```text A: How are you? B: I'm fine, thanks. And you? 👈 此处必须反问 A: Good, thank you. ``` ### 4. **文化差异注意** - ❌ 错误打开方式: ```text A: How are you? B: 我最近工作压力很大,失眠了三天...(过度认真回答) ``` - ✅ 正确理解:这是**社交润滑剂**,不是心理咨询开场白 ### 5. **进阶变体** - 时间限定版: $How\ have\ you\ been\ lately?$ (隐含“我们有一段时间没见了”) - 深度关怀版(需确认关系亲密): $Is\ everything\ okay?\quad$(对方可能真的遇到困难) 建议根据对方的身份(上司/同事/朋友)选择合适的回应方式,避免对陌生人使用过于随意的变体如 *"What's up?"* 。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值