dalao为甚会RE

P1600 [NOIP2016 提高组] 天天爱跑步

bGary @ 2017-09-28 21:39:04

dfs

#include <iostream>
#include <cstring>
using namespace std;
bool vis[101010],flag;
long long a[101010],ans[101010],map[10101][10101],u,v,n,m;
void dfs(long long s,long long e,long long t)
{
    if(flag) return;
    if(vis[s]) return;//cout<<st<<" "<<t<<endl;
    vis[s]=1;
    if(s==e)//if(a[ed]==t) ans[ed]++;
        flag=1;
    if(a[s]==t) ans[s]++;
    for(long long i=1;i<=n;i++)
        if(map[s][i] && !vis[i])
            dfs(i,e,t+1);
}
int main()
{
    cin>>n>>m;
    for(long long i=1;i<n;i++)
    {
        cin>>u>>v;
        map[u][v]=1;
        map[v][u]=1;
    }
    for(long long i=1;i<=n;i++) 
        cin>>a[i];
    for(long long i=1;i<=m;i++)
    {
        memset(vis,0,sizeof(vis));
        flag=0;long long s,e;
        cin>>s>>e;
        dfs(s,e,0);
    }
    for(long long i=1;i<=n;i++) cout<<ans[i]<<" ";
    return 0;
}

/* 6 3 2 3 1 2 1 4 4 5 4 6 0 2 5 1 2 3

1 5 1 3 2 6 */ /* 5 3 1 2 2 3 2 4 1 5 0 1 0 3 0

3 1 1 4 5 5 */


by Victorique @ 2017-09-28 21:54:51

大佬太强辣%%%%%%%%%


by yybyyb @ 2017-09-28 21:58:28

您空间炸了。


by __世界第一弱__ @ 2017-09-28 21:59:18

DFS蔃蔃蔃


by λᴉʍ @ 2017-09-28 22:11:00

8B*10101*10101=816241608B=778.42MB = =不应该MLE吗


by I_AM_HelloWord @ 2017-09-29 20:40:28

MAP数组很爆炸呵


by Humor丶捷 @ 2017-10-25 18:04:42

dfs666


|