用户输出
13 1
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#19582 | #1115. 2-11G. JM的玄学旅社 | Accepted | 100 | 2703 ms | 135916 K | C++ 17 / 2.3 K | LittleFall | 2019-07-19 19:46:51 |
/* LittleFall : Hello! */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline int read();
const int M = 3024, MOD = 1000000007;
int n, m;
vector<int> edg[M];
int dis[M][M];
vector<pair<int, int>> dis_from[M], dis_to[M];
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }
void build() {
n = read(), m = read();
while (m--) {
int a = read(), b = read();
edg[a].push_back(b);
}
memset(dis, -1, sizeof(dis));
for (int s = 1; s <= n; ++s) {
queue<int> q;
q.push(s);
dis[s][s] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : edg[u]) {
if (dis[s][v] == -1) {
q.push(v);
dis[s][v] = dis[s][u] + 1;
}
}
}
// for(int t=1; t<=n; ++t)
// {
// printf("%d ",dis[s][t] );
// }
// printf("\n");
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (dis[i][j] > 0) {
dis_from[i].push_back({ j, dis[i][j] });
dis_to[j].push_back({ i, dis[i][j] });
}
}
}
for (int i = 1; i <= n; ++i) {
sort(dis_from[i].begin(), dis_from[i].end(), cmp);
sort(dis_to[i].begin(), dis_to[i].end(), cmp);
}
}
int main(void) {
#ifdef _LITTLEFALL_
freopen("in.txt", "r", stdin);
#endif
build(); //读入并建图,然后传递闭包
int ans = 0, ans2 = 0;
for (int x2 = 1; x2 <= n; ++x2)
for (int x3 = 1; x3 <= n; ++x3)
if (dis[x2][x3] > 0) {
int t1 = -1, t2 = -1;
for (int i = 0; i < min(3, (int)dis_to[x2].size()); ++i) {
if (dis_to[x2][i].first == x3)
continue;
for (int j = 0; j < min(3, (int)dis_from[x3].size()); ++j) {
auto ex1 = dis_to[x2][i], ex4 = dis_from[x3][j];
if (ex4.first == x2)
continue;
if (ex1.first == ex4.first)
continue;
if (ex1.second + ex4.second > t1 + t2) {
// printf("%d %d %d %d \n",ex1.first,x2,x3,ex4.first );
t1 = ex1.second;
t2 = ex4.second;
}
}
}
if (t1 == -1 || t2 == -1)
continue;
int tmp = t1 + t2 + dis[x2][x3], tmp2 = x2;
if (tmp > ans || (tmp == ans && tmp2 < ans2)) {
// printf("tmp=%d x2=%d x3=%d\n",ans,x2,x3 );
ans = tmp;
ans2 = tmp2;
}
}
cout << ans << " " << ans2 << endl;
return 0;
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
用户输出
13 1
系统信息
Exited with return code 0
用户输出
4 1
系统信息
Exited with return code 0
9 20
2 5
3 2
3 4
4 8
4 4
4 3
4 3
4 3
5 9
5 2
5 1
6 2
6 3
7 1
7 9
7 7
8 9
8 9
9 4
<6 bytes omitted>
用户输出
13 2
系统信息
Exited with return code 0
16 23
1 5
2 16
2 6
2 5
3 16
5 6
5 10
5 5
6 4
6 4
6 9
8 10
9 3
11 2
11 12
11 9
12 14
<38 bytes omitted>
用户输出
14 2
系统信息
Exited with return code 0
4 35
1 1
1 1
1 1
1 4
1 2
1 1
1 1
1 1
1 1
2 4
2 2
2 1
2 4
2 2
2 1
2 4
2 2
2 2
2 3
<81 bytes omitted>
用户输出
5 1
系统信息
Exited with return code 0
8 29
1 7
1 2
1 6
1 6
1 7
2 3
2 2
2 1
3 7
3 6
3 7
4 3
4 8
5 4
5 4
5 7
5 7
6 1
6 3
<51 bytes omitted>
用户输出
12 2
系统信息
Exited with return code 0
用户输出
5 3
系统信息
Exited with return code 0
155 2891
34 112
28 62
145 48
30 66
28 4
99 31
4 70
104 53
131 135
5 59
37 127
66 124
43 115
41 30
6
<18932 bytes omitted>
用户输出
9 1
系统信息
Exited with return code 0
648 4723
6 120
344 200
1 442
58 89
324 164
255 306
393 556
174 596
361 139
568 580
267 9
231 242
335
<36170 bytes omitted>
用户输出
18 37
系统信息
Exited with return code 0
1975 2882
318 170
1821 301
728 505
721 913
1365 1157
1459 672
1950 242
1371 55
1072 809
141 1068
140
<25524 bytes omitted>
用户输出
108 1168
系统信息
Exited with return code 0
2032 3056
315 1657
1844 659
46 236
1835 675
342 746
961 1216
915 523
203 592
1170 938
127 108
217 18
<27211 bytes omitted>
用户输出
98 647
系统信息
Exited with return code 0
3000 5000
2649 200
2603 967
889 1881
1332 2220
1266 1396
400 716
593 478
2106 133
2768 1251
2796 118
<46247 bytes omitted>
用户输出
94 1152
系统信息
Exited with return code 0
3000 5000
181 130
509 499
1771 1501
131 2975
790 62
2583 1938
1035 773
1538 1806
2633 295
406 2217
1
<46264 bytes omitted>
用户输出
91 602
系统信息
Exited with return code 0
2990 3500
1211 1075
539 2609
1676 2371
223 1964
1203 2386
1811 1609
1890 188
2224 1397
732 2718
596
<32270 bytes omitted>
用户输出
93 241
系统信息
Exited with return code 0
3000 4000
1511 2959
567 2183
1026 1949
2034 1021
2852 1665
2441 2170
2503 2261
188 2565
1823 2033
14
<36964 bytes omitted>
用户输出
17 30
系统信息
Exited with return code 0
3000 2999
2712 2915
2294 1910
2794 1980
1940 697
1981 1447
792 2721
150 740
252 166
547 64
1571 2866
<27686 bytes omitted>
用户输出
12 184
系统信息
Exited with return code 0
500 5000
62 170
473 455
341 121
117 343
447 160
436 125
323 48
331 468
343 108
279 250
333 475
121 1
<37757 bytes omitted>
用户输出
15 17
系统信息
Exited with return code 0
1000 1000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
1
<8697 bytes omitted>
用户输出
2997 1
系统信息
Exited with return code 0