Submission #59969

# Submission time Handle Problem Language Result Execution time Memory
59969 2018-07-23T11:46:10 Z dukati8 Duathlon (APIO18_duathlon) C++14
5 / 100
107 ms 636 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[60];
  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];
              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;
  }

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 3 ms 540 KB Output is correct
8 Correct 3 ms 540 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 4 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 4 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 3 ms 616 KB Output is correct
17 Correct 4 ms 616 KB Output is correct
18 Correct 3 ms 616 KB Output is correct
19 Correct 3 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 3 ms 616 KB Output is correct
22 Correct 3 ms 616 KB Output is correct
23 Correct 3 ms 616 KB Output is correct
24 Correct 3 ms 616 KB Output is correct
25 Correct 3 ms 616 KB Output is correct
26 Correct 3 ms 616 KB Output is correct
27 Correct 3 ms 616 KB Output is correct
28 Correct 3 ms 628 KB Output is correct
29 Correct 3 ms 628 KB Output is correct
30 Correct 3 ms 628 KB Output is correct
31 Correct 2 ms 628 KB Output is correct
32 Correct 3 ms 636 KB Output is correct
33 Correct 2 ms 636 KB Output is correct
34 Correct 3 ms 636 KB Output is correct
35 Correct 3 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 3 ms 540 KB Output is correct
8 Correct 3 ms 540 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 4 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 4 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 3 ms 616 KB Output is correct
17 Correct 4 ms 616 KB Output is correct
18 Correct 3 ms 616 KB Output is correct
19 Correct 3 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 3 ms 616 KB Output is correct
22 Correct 3 ms 616 KB Output is correct
23 Correct 3 ms 616 KB Output is correct
24 Correct 3 ms 616 KB Output is correct
25 Correct 3 ms 616 KB Output is correct
26 Correct 3 ms 616 KB Output is correct
27 Correct 3 ms 616 KB Output is correct
28 Correct 3 ms 628 KB Output is correct
29 Correct 3 ms 628 KB Output is correct
30 Correct 3 ms 628 KB Output is correct
31 Correct 2 ms 628 KB Output is correct
32 Correct 3 ms 636 KB Output is correct
33 Correct 2 ms 636 KB Output is correct
34 Correct 3 ms 636 KB Output is correct
35 Correct 3 ms 636 KB Output is correct
36 Correct 25 ms 636 KB Output is correct
37 Correct 26 ms 636 KB Output is correct
38 Incorrect 107 ms 636 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 3 ms 540 KB Output is correct
8 Correct 3 ms 540 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 4 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 4 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 3 ms 616 KB Output is correct
17 Correct 4 ms 616 KB Output is correct
18 Correct 3 ms 616 KB Output is correct
19 Correct 3 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 3 ms 616 KB Output is correct
22 Correct 3 ms 616 KB Output is correct
23 Correct 3 ms 616 KB Output is correct
24 Correct 3 ms 616 KB Output is correct
25 Correct 3 ms 616 KB Output is correct
26 Correct 3 ms 616 KB Output is correct
27 Correct 3 ms 616 KB Output is correct
28 Correct 3 ms 628 KB Output is correct
29 Correct 3 ms 628 KB Output is correct
30 Correct 3 ms 628 KB Output is correct
31 Correct 2 ms 628 KB Output is correct
32 Correct 3 ms 636 KB Output is correct
33 Correct 2 ms 636 KB Output is correct
34 Correct 3 ms 636 KB Output is correct
35 Correct 3 ms 636 KB Output is correct
36 Correct 25 ms 636 KB Output is correct
37 Correct 26 ms 636 KB Output is correct
38 Incorrect 107 ms 636 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 3 ms 540 KB Output is correct
7 Correct 3 ms 540 KB Output is correct
8 Correct 3 ms 540 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 4 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 4 ms 616 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 3 ms 616 KB Output is correct
15 Correct 3 ms 616 KB Output is correct
16 Correct 3 ms 616 KB Output is correct
17 Correct 4 ms 616 KB Output is correct
18 Correct 3 ms 616 KB Output is correct
19 Correct 3 ms 616 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 3 ms 616 KB Output is correct
22 Correct 3 ms 616 KB Output is correct
23 Correct 3 ms 616 KB Output is correct
24 Correct 3 ms 616 KB Output is correct
25 Correct 3 ms 616 KB Output is correct
26 Correct 3 ms 616 KB Output is correct
27 Correct 3 ms 616 KB Output is correct
28 Correct 3 ms 628 KB Output is correct
29 Correct 3 ms 628 KB Output is correct
30 Correct 3 ms 628 KB Output is correct
31 Correct 2 ms 628 KB Output is correct
32 Correct 3 ms 636 KB Output is correct
33 Correct 2 ms 636 KB Output is correct
34 Correct 3 ms 636 KB Output is correct
35 Correct 3 ms 636 KB Output is correct
36 Correct 25 ms 636 KB Output is correct
37 Correct 26 ms 636 KB Output is correct
38 Incorrect 107 ms 636 KB Output isn't correct
39 Halted 0 ms 0 KB -