A

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int Maxn = 1e6+10;
const int Inf = 0x7f7f7f7f;
const int Mod = 998244353;

int n,m;
char s[12000010];
priority_queue<int,vector<int> ,greater<int> > Map[Maxn];

ll ans[Maxn];
bool vis[Maxn];

void dfs(int s,ll c){
    while( !Map[s].empty() )
    {
        int u = Map[s].top();Map[s].pop();
        if( vis[u] )  continue;
        ll tmp = (c*1000000 + u)%Mod;
        ans[u] = tmp;
        vis[u] = true;
        dfs(u,tmp);
    }
}

int main(){
    scanf("%d %d",&n,&m);
    if( m == 0 )
    {
        for(int i=2;i<=n;i++)
            puts("-1");
        return 0;
    }
    scanf("%s",s);
    int len = strlen(s);
    for(int i=0,u=0,v=0;i<len;i+=12)
    {
        u = 0,v = 0;
        for(int j=0;j<6;j++)
            u = u*10+s[i+j]-'0';
        for(int j=6;j<12;j++)
            v = v*10+s[i+j]-'0';
        Map[u].push(v);
        Map[v].push(u);
    }
    vis[0] = true;
    dfs(0,0);
    for(int i=1;i<n;i++)
        if( vis[i] )  printf("%lld\n",ans[i]);
        else puts("-1");
    return 0;
}

原文链接: https://www.cnblogs.com/HexQwQ/p/12943389.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    A

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/350358

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月2日 上午6:17
下一篇 2023年3月2日 上午6:17

相关推荐