제출 #432487

#제출 시각아이디문제언어결과실행 시간메모리
432487SuhaibSawalha1철인 이종 경기 (APIO18_duathlon)C++17
0 / 100
2 ms332 KiB
#include <bits/stdc++.h>
using namespace std;
 
int n, m, nodes, vid, found;
vector<vector<int>> adj;
vector<int> vis;
long long ans;
 
void dfs (int u, int t, int k, bool ok = 0) {
  if (found) {
    return;
  }
  vis[u] = vid;
  if (u == k) {
    found = ok;
    ans += ok;
  }
  ok |= u == t;
  for (int v : adj[u]) {
    if (vis[v] != vid) {
      dfs(v, t, k, ok);
    }
  }
  vis[u] = 0;
}

bool cycle;

void dfs2 (int u, int p = -1) {
  vis[u] = 1;
  ++nodes;
  for (int v : adj[u]) {
    if (!vis[v]) {
      dfs2(v, u);
    }
    else if (v ^ p) {
      cycle = 1;
    }
  }
}
    
int main (){
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
  freopen("SuhaibSawalha1","r",stdin);

  cin >> n >> m;
  adj.resize(n);
  while (m--) {
    int u, v;
    cin >> u >> v, --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }    
  vis.resize(n);
  if (n <= 10) {
    for (int u = 0; u < n; ++u) {
      for (int v = 0; v < n; ++v) {
        for (int k = 0; k < n; ++k) {
          if (set<int>{u, v, k}.size() == 3) {
            ++vid;
            found = 0;
            dfs(u, v, k);
          }
        }
      }
    }
    cout << ans;
    return 0;
  }
  for (int u = 0; u < n; ++u) {
    if (!vis[u]) {
      nodes = cycle = 0;
      dfs2(u);
      if (cycle) {
        ans += nodes * 1LL * (nodes - 1) * (nodes - 2);
      }
      else {
        ans += nodes * 1LL * (nodes - 1) * (nodes - 2) / 3;
      }
    }
  }
  cout << ans;
 
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:47:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |   freopen("SuhaibSawalha1","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...