编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#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;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:30 ms
内存:36212 KiB

输入文件(1.in

8 9
1 2
2 3
3 4
4 1
4 5
5 6
6 7
7 8
8 5

答案文件(1.out

13 1

用户输出

13 1

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:28 ms
内存:36216 KiB

输入文件(2.in

6 16
1 4
1 4
1 1
1 2
2 6
3 3
3 4
3 3
4 6
4 6
5 1
5 2
5 5
5 5
5 2
6 4

答案文件(2.out

4 1

用户输出

4 1

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:28 ms
内存:36236 KiB

输入文件(3.in

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>

答案文件(3.out

13 2

用户输出

13 2

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:29 ms
内存:36144 KiB

输入文件(4.in

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>

答案文件(4.out

14 2

用户输出

14 2

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:29 ms
内存:36216 KiB

输入文件(5.in

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.out

5 1

用户输出

5 1

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:30 ms
内存:36212 KiB

输入文件(6.in

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>

答案文件(6.out

12 2

用户输出

12 2

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:35 ms
内存:36140 KiB

输入文件(7.in

12 11
1 12
12 3
3 4
4 5
5 6
7 6
7 8
8 9
9 10
10 11
11 2

答案文件(7.out

5 3

用户输出

5 3

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:28 ms
内存:36144 KiB

输入文件(8.in

4 6
1 2
1 3
1 4
2 3
3 4
4 2

答案文件(8.out

5 2

用户输出

5 2

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:32 ms
内存:36880 KiB

输入文件(9.in

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.out

9 1

用户输出

9 1

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:98 ms
内存:46772 KiB

输入文件(10.in

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>

答案文件(10.out

18 37

用户输出

18 37

系统信息

Exited with return code 0
测试点 #11
Accepted
得分:100
用时:180 ms
内存:52660 KiB

输入文件(11.in

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>

答案文件(11.out

108 1168

用户输出

108 1168

系统信息

Exited with return code 0
测试点 #12
Accepted
得分:100
用时:207 ms
内存:59844 KiB

输入文件(12.in

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>

答案文件(12.out

98 647

用户输出

98 647

系统信息

Exited with return code 0
测试点 #13
Accepted
得分:100
用时:681 ms
内存:101128 KiB

输入文件(13.in

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>

答案文件(13.out

94 1152

用户输出

94 1152

系统信息

Exited with return code 0
测试点 #14
Accepted
得分:100
用时:782 ms
内存:135916 KiB

输入文件(14.in

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>

答案文件(14.out

91 602

用户输出

91 602

系统信息

Exited with return code 0
测试点 #15
Accepted
得分:100
用时:81 ms
内存:40640 KiB

输入文件(15.in

2990 3500
1211 1075
539 2609
1676 2371
223 1964
1203 2386
1811 1609
1890 188
2224 1397
732 2718
596 
<32270 bytes omitted>

答案文件(15.out

93 241

用户输出

93 241

系统信息

Exited with return code 0
测试点 #16
Accepted
得分:100
用时:51 ms
内存:37084 KiB

输入文件(16.in

3000 4000
1511 2959
567 2183
1026 1949
2034 1021
2852 1665
2441 2170
2503 2261
188 2565
1823 2033
14
<36964 bytes omitted>

答案文件(16.out

17 30

用户输出

17 30

系统信息

Exited with return code 0
测试点 #17
Accepted
得分:100
用时:49 ms
内存:36472 KiB

输入文件(17.in

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>

答案文件(17.out

12 184

用户输出

12 184

系统信息

Exited with return code 0
测试点 #18
Accepted
得分:100
用时:66 ms
内存:40360 KiB

输入文件(18.in

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>

答案文件(18.out

15 17

用户输出

15 17

系统信息

Exited with return code 0
测试点 #19
Accepted
得分:100
用时:210 ms
内存:52436 KiB

输入文件(19.in

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>

答案文件(19.out

2997 1

用户输出

2997 1

系统信息

Exited with return code 0
测试点 #20
Accepted
得分:100
用时:29 ms
内存:36152 KiB

输入文件(20.in

5 5
1 4
4 5
5 2
2 3
3 1

答案文件(20.out

12 1

用户输出

12 1

系统信息

Exited with return code 0