Submission #58270

# Submission time Handle Problem Language Result Execution time Memory
58270 2018-07-17T10:32:40 Z evpipis 007 (CEOI14_007) C++14
0 / 100
1000 ms 15820 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

const int len = 2e5+5, inf = 1e9;
int dis[len], tim[len];
int n, m, s1, s2, t1, t2;
queue<int> myq;
vector<int> adj[len];

void bfs(int st){
    for (int i = 1; i <= n; i++)
        dis[i] = -1;

    dis[st] = 0, myq.push(st);
    while (!myq.empty()){
        int u = myq.front();
        myq.pop();

        for (int j = 0; j < adj[u].size(); j++){
            int v = adj[u][j];
            if (dis[v] == -1)
                dis[v] = dis[u]+1, myq.push(v);
        }
    }
}

int main(){
    scanf("%d %d %d %d %d %d", &n, &m, &s1, &s2, &t1, &t2);
    for (int i = 0; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    int a1, a2, b1, b2, w1, w2;
    bfs(t1);
    a1 = dis[s1], b1 = dis[s2], w1 = b1-a1;

    bfs(t2);
    a2 = dis[s1], b2 = dis[s2], w2 = b2-a2;

    if (w1 > w2)
        swap(a1, a2), swap(b1, b2), swap(w1, w2);

    if (b1 == b2 && a1 == a2)
        while (true){}
    else
        printf("%d\n", w1);
    return 0;
}

/*
9 10
9 8 1 2
1 2
2 3
3 1
2 4
4 5
5 2
5 7
7 6
7 8
7 9

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

6 7
5 6 1 2
6 3
1 2
1 3
2 3
1 5
2 4
5 4
*/

Compilation message

007.cpp: In function 'void bfs(int)':
007.cpp:26:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < adj[u].size(); j++){
                         ~~^~~~~~~~~~~~~~~
007.cpp: In function 'int main()':
007.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d %d %d", &n, &m, &s1, &s2, &t1, &t2);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 6 ms 5220 KB Output is correct
3 Execution timed out 1088 ms 5220 KB Time limit exceeded
4 Execution timed out 1070 ms 5220 KB Time limit exceeded
5 Execution timed out 1043 ms 5220 KB Time limit exceeded
6 Execution timed out 1084 ms 5220 KB Time limit exceeded
7 Execution timed out 1087 ms 5240 KB Time limit exceeded
8 Execution timed out 1082 ms 5240 KB Time limit exceeded
9 Execution timed out 1079 ms 5240 KB Time limit exceeded
10 Correct 5 ms 5240 KB Output is correct
11 Correct 6 ms 5264 KB Output is correct
12 Execution timed out 1056 ms 5264 KB Time limit exceeded
13 Execution timed out 1066 ms 5264 KB Time limit exceeded
14 Execution timed out 1085 ms 5264 KB Time limit exceeded
15 Execution timed out 1090 ms 5360 KB Time limit exceeded
16 Execution timed out 1089 ms 5360 KB Time limit exceeded
17 Execution timed out 1069 ms 5360 KB Time limit exceeded
18 Execution timed out 1066 ms 5360 KB Time limit exceeded
19 Execution timed out 1054 ms 5360 KB Time limit exceeded
20 Execution timed out 1073 ms 5360 KB Time limit exceeded
21 Correct 6 ms 5360 KB Output is correct
22 Execution timed out 1084 ms 5380 KB Time limit exceeded
23 Execution timed out 1085 ms 5380 KB Time limit exceeded
24 Execution timed out 1075 ms 5380 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 6652 KB Time limit exceeded
2 Execution timed out 1084 ms 7292 KB Time limit exceeded
3 Execution timed out 1081 ms 7292 KB Time limit exceeded
4 Execution timed out 1058 ms 7420 KB Time limit exceeded
5 Correct 29 ms 7420 KB Output is correct
6 Correct 40 ms 7420 KB Output is correct
7 Execution timed out 1076 ms 7420 KB Time limit exceeded
8 Execution timed out 1085 ms 7420 KB Time limit exceeded
9 Execution timed out 1069 ms 7420 KB Time limit exceeded
10 Execution timed out 1080 ms 11772 KB Time limit exceeded
11 Execution timed out 1075 ms 11772 KB Time limit exceeded
12 Execution timed out 1080 ms 11772 KB Time limit exceeded
13 Execution timed out 1077 ms 11772 KB Time limit exceeded
14 Execution timed out 1084 ms 11772 KB Time limit exceeded
15 Execution timed out 1089 ms 11772 KB Time limit exceeded
16 Correct 85 ms 11772 KB Output is correct
17 Execution timed out 1060 ms 11772 KB Time limit exceeded
18 Execution timed out 1064 ms 11772 KB Time limit exceeded
19 Execution timed out 1054 ms 11772 KB Time limit exceeded
20 Execution timed out 1064 ms 13168 KB Time limit exceeded
21 Execution timed out 1086 ms 13168 KB Time limit exceeded
22 Execution timed out 1086 ms 13168 KB Time limit exceeded
23 Correct 108 ms 13168 KB Output is correct
24 Execution timed out 1087 ms 13168 KB Time limit exceeded
25 Execution timed out 1073 ms 13168 KB Time limit exceeded
26 Correct 164 ms 13168 KB Output is correct
27 Execution timed out 1064 ms 13168 KB Time limit exceeded
28 Execution timed out 1087 ms 13168 KB Time limit exceeded
29 Execution timed out 1084 ms 13168 KB Time limit exceeded
30 Execution timed out 1084 ms 13664 KB Time limit exceeded
31 Execution timed out 1080 ms 13664 KB Time limit exceeded
32 Execution timed out 1081 ms 13664 KB Time limit exceeded
33 Correct 109 ms 13664 KB Output is correct
34 Execution timed out 1076 ms 13664 KB Time limit exceeded
35 Execution timed out 1085 ms 13664 KB Time limit exceeded
36 Execution timed out 1070 ms 13664 KB Time limit exceeded
37 Correct 202 ms 13664 KB Output is correct
38 Execution timed out 1059 ms 13664 KB Time limit exceeded
39 Execution timed out 1085 ms 13664 KB Time limit exceeded
40 Execution timed out 1083 ms 13664 KB Time limit exceeded
41 Execution timed out 1081 ms 15820 KB Time limit exceeded