답안 #955449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955449 2024-03-30T13:08:27 Z hariaakas646 007 (CEOI14_007) C++14
0 / 100
176 ms 22976 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int n, m;
vvi graph;

vi bfs(int x) {
    vi dist(n+1, 1e9);
    vb vis(n+1);
    queue<pii> q;
    q.push(mp(x, 0));
    while(q.size()) {
        auto p = q.front();
        q.pop();
        if(vis[p.f]) continue;
        // printf("%d\n", p.f);
        vis[p.f] = true;
        dist[p.f] = p.s;
        for(auto e : graph[p.f]) {
            // printf("%d ", e);
            q.push(mp(e, p.s+1));
        }
    }
    return dist;
}

int main() {
    // usaco();
    scd(n); scd(m);
    int s1, s2, a, b;
    scd(s1);
    scd(s2);
    scd(a);
    scd(b);
    graph = vvi(n+1);

    frange(i, m) {
        int a, b;
        scd(a);
        scd(b);
        graph[a].pb(b);
        graph[b].pb(a);
    }

    vi dist1 = bfs(s1);
    vi dist2 = bfs(s2);
    // printf("%d %d %d %d\n", dist1[a], dist1[b], dist2[a], dist2[b]);

    if(dist1[a] > dist2[a] || dist1[b] > dist2[b]) printf("-1");
    else {
        // if(dist2[a] == dist2[b] && dist1[a] == dist1[b]) dist1[a]++;
        printf("%d", min(dist2[a]-dist1[a], dist2[b]-dist1[b]));
    }

}

Compilation message

007.cpp: In function 'void usaco()':
007.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp: In function 'int main()':
007.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
007.cpp:59:5: note: in expansion of macro 'scd'
   59 |     scd(n); scd(m);
      |     ^~~
007.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
007.cpp:59:13: note: in expansion of macro 'scd'
   59 |     scd(n); scd(m);
      |             ^~~
007.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
007.cpp:61:5: note: in expansion of macro 'scd'
   61 |     scd(s1);
      |     ^~~
007.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
007.cpp:62:5: note: in expansion of macro 'scd'
   62 |     scd(s2);
      |     ^~~
007.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
007.cpp:63:5: note: in expansion of macro 'scd'
   63 |     scd(a);
      |     ^~~
007.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
007.cpp:64:5: note: in expansion of macro 'scd'
   64 |     scd(b);
      |     ^~~
007.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
007.cpp:69:9: note: in expansion of macro 'scd'
   69 |         scd(a);
      |         ^~~
007.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
007.cpp:70:9: note: in expansion of macro 'scd'
   70 |         scd(b);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Correct 1 ms 348 KB Output is correct
16 Incorrect 1 ms 348 KB Output isn't correct
17 Incorrect 1 ms 440 KB Output isn't correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Incorrect 1 ms 348 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3420 KB Output is correct
2 Incorrect 26 ms 4928 KB Output isn't correct
3 Correct 14 ms 3460 KB Output is correct
4 Incorrect 18 ms 4952 KB Output isn't correct
5 Correct 16 ms 3196 KB Output is correct
6 Correct 13 ms 3676 KB Output is correct
7 Correct 15 ms 3932 KB Output is correct
8 Correct 15 ms 3924 KB Output is correct
9 Incorrect 24 ms 4956 KB Output isn't correct
10 Correct 104 ms 13788 KB Output is correct
11 Incorrect 28 ms 7000 KB Output isn't correct
12 Correct 38 ms 8860 KB Output is correct
13 Incorrect 30 ms 7768 KB Output isn't correct
14 Correct 25 ms 6532 KB Output is correct
15 Correct 35 ms 9040 KB Output is correct
16 Correct 38 ms 9416 KB Output is correct
17 Correct 33 ms 8540 KB Output is correct
18 Incorrect 35 ms 8540 KB Output isn't correct
19 Correct 60 ms 11044 KB Output is correct
20 Incorrect 123 ms 16828 KB Output isn't correct
21 Incorrect 50 ms 12372 KB Output isn't correct
22 Correct 44 ms 10636 KB Output is correct
23 Correct 57 ms 12372 KB Output is correct
24 Correct 49 ms 12144 KB Output is correct
25 Incorrect 50 ms 11472 KB Output isn't correct
26 Correct 44 ms 10832 KB Output is correct
27 Correct 50 ms 12368 KB Output is correct
28 Correct 60 ms 12368 KB Output is correct
29 Correct 86 ms 13912 KB Output is correct
30 Incorrect 132 ms 18280 KB Output isn't correct
31 Incorrect 62 ms 14256 KB Output isn't correct
32 Correct 57 ms 12372 KB Output is correct
33 Correct 51 ms 12624 KB Output is correct
34 Incorrect 57 ms 13392 KB Output isn't correct
35 Incorrect 53 ms 12744 KB Output isn't correct
36 Incorrect 52 ms 13136 KB Output isn't correct
37 Correct 62 ms 14932 KB Output is correct
38 Correct 64 ms 14580 KB Output is correct
39 Correct 64 ms 14832 KB Output is correct
40 Incorrect 112 ms 18004 KB Output isn't correct
41 Correct 176 ms 22976 KB Output is correct