Submission #59965

# Submission time Handle Problem Language Result Execution time Memory
59965 2018-07-23T11:35:38 Z dukati8 Duathlon (APIO18_duathlon) C++14
5 / 100
118 ms 624 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];
              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;
  }

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 0 ms 536 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 3 ms 560 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 4 ms 600 KB Output is correct
17 Correct 4 ms 600 KB Output is correct
18 Correct 4 ms 600 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 4 ms 600 KB Output is correct
23 Correct 3 ms 600 KB Output is correct
24 Correct 3 ms 600 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 4 ms 600 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 3 ms 600 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 3 ms 600 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 0 ms 536 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 3 ms 560 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 4 ms 600 KB Output is correct
17 Correct 4 ms 600 KB Output is correct
18 Correct 4 ms 600 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 4 ms 600 KB Output is correct
23 Correct 3 ms 600 KB Output is correct
24 Correct 3 ms 600 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 4 ms 600 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 3 ms 600 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 3 ms 600 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 22 ms 600 KB Output is correct
37 Correct 28 ms 600 KB Output is correct
38 Incorrect 118 ms 624 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 0 ms 536 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 3 ms 560 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 4 ms 600 KB Output is correct
17 Correct 4 ms 600 KB Output is correct
18 Correct 4 ms 600 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 4 ms 600 KB Output is correct
23 Correct 3 ms 600 KB Output is correct
24 Correct 3 ms 600 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 4 ms 600 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 3 ms 600 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 3 ms 600 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 22 ms 600 KB Output is correct
37 Correct 28 ms 600 KB Output is correct
38 Incorrect 118 ms 624 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 0 ms 536 KB Output is correct
7 Correct 3 ms 536 KB Output is correct
8 Correct 3 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 2 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 3 ms 560 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 4 ms 600 KB Output is correct
17 Correct 4 ms 600 KB Output is correct
18 Correct 4 ms 600 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 4 ms 600 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 4 ms 600 KB Output is correct
23 Correct 3 ms 600 KB Output is correct
24 Correct 3 ms 600 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 4 ms 600 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 3 ms 600 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 2 ms 600 KB Output is correct
31 Correct 3 ms 600 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 3 ms 600 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 22 ms 600 KB Output is correct
37 Correct 28 ms 600 KB Output is correct
38 Incorrect 118 ms 624 KB Output isn't correct
39 Halted 0 ms 0 KB -