H 的屍山是怎樣煉成的
前言
看來…是怎樣煉成的已經成了梗叻。
京爺不是不能使用繁體字的。不過為了大家閱讀順暢,就此打住咯!
解题思路
懒得写。毕竟目前所知申请不了本题题解。家人们也是开了2个并查集维护航司和航班叻。
代码呈现
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_map>
using namespace std;
unordered_map<string, int> mp;
template <int sz>
struct Dsu {
int f[sz + 3], n = 0;
Dsu() {
for (int i = 1; i <= sz; i ++) {
f[i] = i;
}
}
int find(int x) {
return x == f[x] ? x : f[x] = find(f[x]);
}
void merge(int x, int y) {
f[x] = f[y];
}
int cnt() {
set<int> a;
for (int i = 1; i <= n; i ++) {
a.insert(find(i));
}
return a.size();
}
};
struct Flight {
string co, dep, des;
int no, h, m;
} a[105];
Dsu<105> company, flight;
bool operator == (Flight a, Flight b) {
return (string)a.dep == (string)b.dep && (string)a.des == (string)b.des && a.h == b.h && a.m == b.m && company.find(mp[(string)a.co]) == company.find(mp[(string)b.co]);
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i ++) {
int c;
string s, t;
cin >> c >> t;
mp[t] = ++ company.n;
for (int j = 1; j < c; j ++) {
cin >> s;
mp[s] = ++ company.n;
company.merge(company.n, mp[t]);
}
}
flight.n = n;
getchar();
for (int i = 1; i <= n; i ++) {
string s;
getline(cin, s, '-');
a[i].co = s.substr(0, 2);
getline(cin, a[i].dep, '-');
getline(cin, a[i].des, '-');
scanf("%d:%d", &a[i].h, &a[i].m);
getchar();
if (!mp.count((string)a[i].co)) {
mp[(string)a[i].co] = ++ company.n;
}
for (int j = 1; j < i; j ++) {
if (a[j] == a[i]) {
flight.merge(i, j);
}
}
}
cout << flight.cnt();
return 0;
}