文章

99

粉丝

120

获赞

8

访问

97.5k

头像
Head of a Gang
备考心情
发布于2024年8月9日 11:30
阅读数 970

#include <iostream>
#include <map>
using namespace std;
map<string, int> stringToInt;
map<int, string> intToString;
map<string, int> ans;
int idNumber = 1, k;
int stoifunc(string s) {
    if (stringToInt[s] == 0) {
        stringToInt[s] = idNumber;
        intToString[idNumber] = s;
        return idNumber++;
    }
    else {
        return stringToInt[s];
    }
}
int G[2010][2010], weight[2010];
bool vis[2010];
void dfs(int u, int& head, int& numMember, int& totalweight) {
    vis[u] = true;
    numMember++;
    if (weight[u] > weight[head])
        head = u;
    for (int v = 1; v < idNumber; v++) {
        if (G[u][v] > 0) {
            totalweight += G[u][v];
            G[u][v] = G[v][u] = 0;
            if (vis[v] == false)
                dfs(v, head, numMember, totalweight);
        }
    }
}
void dfsTrave() {
    for (int i = 1; i < idNumber; i++) {
        if (vis[i] == false) {
   ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发