답안 #59963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59963 2018-07-23T11:33:52 Z dukati8 철인 이종 경기 (APIO18_duathlon) C++14
5 / 100
132 ms 852 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a; i<int(b); i++)
#define all(x) x.begin(),x.end()
bool flags[100000];
bool visits[100000];
vector<pair<int,int> > roads;
vector< vector<int> > close;
bool dfs(int curr, int goal) {
  if (curr==goal) {flags[curr]=true; return true;}
  visits[curr]=true;
  for (auto a:close[curr]) {
    if (!visits[a]) {
      if (dfs(a,goal)) {flags[curr]=true; return true;}
    }
  }
  return false;
}
bool bfs(int start, int goal) {
  queue<int> order;
  order.push(start);
  int from[50];
  while (!order.empty()) {
    int now = order.front();
    order.pop();
    if (now==goal) {
      flags[now]=true;
      while (now!=start){
        now=from[now];
        flags[now]=true;
      }
      return true;
    }
    for (auto a:close[now]) {
      if (!visits[a]) {
        from[a]=now;
        order.push(a);
        visits[a]=true;
      }
    }
  }
  return false;
}
int main() {
  int n,m;
  cin >>n >>m;
  if (n<=50) {
    close.assign(n,vector<int>());
    rep(i,0,m) {
      int u,v;
      cin >> u >> v;
      u--;v--;
      roads.push_back(make_pair(u,v));
      close[u].push_back(v);
      close[v].push_back(u);
    }
    int count=0;
    rep(i,0,n) {
      rep (j,0,n) {
        rep (k,0,n) {
          if (i!=j && j!=k && i!=k) {
            //search route i to j and j to k, and if not works try other way instead.
            rep (x,0,n) {visits[x]=false; flags[x]=false;}
            if (bfs(i,j)) {
              rep (x,0,n) visits[x]=flags[x];
              visits[j]=false;
              if (bfs(j,k)) {count++;}
              else {
                rep (x,0,n) {visits[x]=false; flags[x]=false;}
                if (bfs(j,k)) {
                  rep (x,0,n) visits[x]=flags[x];
                  if (bfs(j,i)) {count++;}
                }
              }
            }
          }
        }
      }
    }
    cout << count << endl;
  }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 3 ms 508 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
12 Correct 4 ms 608 KB Output is correct
13 Correct 4 ms 608 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 4 ms 616 KB Output is correct
16 Correct 4 ms 616 KB Output is correct
17 Correct 3 ms 628 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 4 ms 652 KB Output is correct
22 Correct 3 ms 668 KB Output is correct
23 Correct 3 ms 672 KB Output is correct
24 Correct 2 ms 676 KB Output is correct
25 Correct 3 ms 676 KB Output is correct
26 Correct 4 ms 676 KB Output is correct
27 Correct 3 ms 676 KB Output is correct
28 Correct 4 ms 676 KB Output is correct
29 Correct 3 ms 676 KB Output is correct
30 Correct 2 ms 676 KB Output is correct
31 Correct 4 ms 676 KB Output is correct
32 Correct 4 ms 676 KB Output is correct
33 Correct 3 ms 676 KB Output is correct
34 Correct 2 ms 852 KB Output is correct
35 Correct 2 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 3 ms 508 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
12 Correct 4 ms 608 KB Output is correct
13 Correct 4 ms 608 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 4 ms 616 KB Output is correct
16 Correct 4 ms 616 KB Output is correct
17 Correct 3 ms 628 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 4 ms 652 KB Output is correct
22 Correct 3 ms 668 KB Output is correct
23 Correct 3 ms 672 KB Output is correct
24 Correct 2 ms 676 KB Output is correct
25 Correct 3 ms 676 KB Output is correct
26 Correct 4 ms 676 KB Output is correct
27 Correct 3 ms 676 KB Output is correct
28 Correct 4 ms 676 KB Output is correct
29 Correct 3 ms 676 KB Output is correct
30 Correct 2 ms 676 KB Output is correct
31 Correct 4 ms 676 KB Output is correct
32 Correct 4 ms 676 KB Output is correct
33 Correct 3 ms 676 KB Output is correct
34 Correct 2 ms 852 KB Output is correct
35 Correct 2 ms 852 KB Output is correct
36 Correct 34 ms 852 KB Output is correct
37 Correct 42 ms 852 KB Output is correct
38 Incorrect 132 ms 852 KB Output isn't correct
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 3 ms 508 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
12 Correct 4 ms 608 KB Output is correct
13 Correct 4 ms 608 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 4 ms 616 KB Output is correct
16 Correct 4 ms 616 KB Output is correct
17 Correct 3 ms 628 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 4 ms 652 KB Output is correct
22 Correct 3 ms 668 KB Output is correct
23 Correct 3 ms 672 KB Output is correct
24 Correct 2 ms 676 KB Output is correct
25 Correct 3 ms 676 KB Output is correct
26 Correct 4 ms 676 KB Output is correct
27 Correct 3 ms 676 KB Output is correct
28 Correct 4 ms 676 KB Output is correct
29 Correct 3 ms 676 KB Output is correct
30 Correct 2 ms 676 KB Output is correct
31 Correct 4 ms 676 KB Output is correct
32 Correct 4 ms 676 KB Output is correct
33 Correct 3 ms 676 KB Output is correct
34 Correct 2 ms 852 KB Output is correct
35 Correct 2 ms 852 KB Output is correct
36 Correct 34 ms 852 KB Output is correct
37 Correct 42 ms 852 KB Output is correct
38 Incorrect 132 ms 852 KB Output isn't correct
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 3 ms 508 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
12 Correct 4 ms 608 KB Output is correct
13 Correct 4 ms 608 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 4 ms 616 KB Output is correct
16 Correct 4 ms 616 KB Output is correct
17 Correct 3 ms 628 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 4 ms 652 KB Output is correct
22 Correct 3 ms 668 KB Output is correct
23 Correct 3 ms 672 KB Output is correct
24 Correct 2 ms 676 KB Output is correct
25 Correct 3 ms 676 KB Output is correct
26 Correct 4 ms 676 KB Output is correct
27 Correct 3 ms 676 KB Output is correct
28 Correct 4 ms 676 KB Output is correct
29 Correct 3 ms 676 KB Output is correct
30 Correct 2 ms 676 KB Output is correct
31 Correct 4 ms 676 KB Output is correct
32 Correct 4 ms 676 KB Output is correct
33 Correct 3 ms 676 KB Output is correct
34 Correct 2 ms 852 KB Output is correct
35 Correct 2 ms 852 KB Output is correct
36 Correct 34 ms 852 KB Output is correct
37 Correct 42 ms 852 KB Output is correct
38 Incorrect 132 ms 852 KB Output isn't correct
39 Halted 0 ms 0 KB -