forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
145 lines (121 loc) · 3.71 KB
/
C.cpp
File metadata and controls
145 lines (121 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <bits/stdc++.h>
#define int long long
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define SZ(x) ((int) (x).size())
using namespace std;
const int MN = 100111;
const int MOD = 1e9 + 7;
struct Hash {
int x, y;
Hash() : x(0), y(0) {}
Hash(int x, int y) : x(x), y(y) {}
Hash operator + (const Hash& a) const {
return Hash(x + a.x, (y + a.y) % MOD);
}
Hash operator - (const Hash& a) const {
return Hash(x - a.x, (y - a.y + MOD) % MOD);
}
Hash operator * (const Hash& a) const {
return Hash(x * a.x, y * a.y % MOD);
}
Hash extend(char c) {
return Hash(x * 311 + c, (y * 311 + c) % MOD);
}
friend ostream& operator << (ostream& cout, Hash& h) {
cout << '(' << h.x << ' ' << h.y << ')';
return cout;
}
};
bool operator < (const Hash& a, const Hash& b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
bool operator == (const Hash& a, const Hash& b) {
return a.x == b.x && a.y == b.y;
}
map<string,int> siteId;
pair<vector<Hash>,int> sitePaths[MN];
string siteName[MN];
int nPath, nSite;
void init() {
nSite = 0;
siteId.clear();
REP(i,MN) sitePaths[i].first.clear();
}
char tmp[100111];
pair<string,string> splitPath(string s) {
int slash = 0, third = 0;
REP(i,SZ(s)) {
char c = s[i];
if (c != '/') continue;
++slash;
if (slash == 3) third = i;
}
if (slash < 3) {
return make_pair(s, "");
}
return make_pair(s.substr(0, third), s.substr(third));
}
int getId(string s) {
if (siteId.count(s)) return siteId[s];
int x = SZ(siteId) + 1;
siteName[x] = s;
siteId[s] = x;
return x;
}
Hash getHash(string s) {
Hash res;
for(char c : s) res = res.extend(c);
return res;
}
#undef int
int main() {
#define int long long
ios :: sync_with_stdio(0); cin.tie(0);
while (scanf("%lld\n", &nPath) == 1) {
init();
FOR(i,1,nPath) {
scanf("%s\n", &tmp[0]);
string s(tmp);
auto t = splitPath(s);
int id = getId(t.first);
sitePaths[id].first.push_back(getHash(t.second));
}
int nSite = SZ(siteId);
FOR(i,1,nSite) {
sort(sitePaths[i].first.begin(), sitePaths[i].first.end());
sitePaths[i].second = i;
sitePaths[i].first.resize(
unique(sitePaths[i].first.begin(), sitePaths[i].first.end()) - sitePaths[i].first.begin());
}
sort(sitePaths+1, sitePaths+nSite+1);
// FOR(i,1,nSite) {
// PR0(sitePaths[i].first, SZ(sitePaths[i].first));
// }
int i = 1, cnt = 0;
while (i <= nSite) {
int j = i;
while (j < nSite && sitePaths[j+1].first == sitePaths[j].first) ++j;
if (j > i) ++cnt;
i = j + 1;
}
cout << cnt << endl;
i = 1;
while (i <= nSite) {
int j = i;
while (j < nSite && sitePaths[j+1].first == sitePaths[j].first) ++j;
if (j > i) {
FOR(x,i,j) printf("%s ", siteName[sitePaths[x].second].c_str());
puts("");
}
i = j + 1;
}
}
}