Submission #260545

# Submission time Handle Problem Language Result Execution time Memory
260545 2020-08-10T13:57:04 Z Nucleist Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 1048580 KB
//Self-control leads to consistency.
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
ll cum[200001],dp[200001],dp2[200001];
ve gr[200001];
ll dfs(ll node,ll p){
  ll ans=1;
  for(auto it:gr[node]){
    if(it!=p && cum[it]==0){
      ans+=dfs(it,node);
    }
  }
  ll ans1=0;
  ll ans2=0;
  ll ans3=0;
  for(auto it:gr[node]){
    if(it!=p){
      ans1+=(cum[it]-1);
      ans2+=cum[it];
      ans3+=cum[it]*cum[it];
      dp2[node]+=dp2[it];
    }
  }
  ans1*=2;
  ans2*=ans2;
  ans2-=ans3;
  dp2[node]+=ans1;
  dp[node]+=ans2;
  dp[node]+=dp2[node];
  return cum[node]=ans;
}
int main()
{
  flash;
  ll n,m;
  cin>>n>>m;
  for (ll i = 0; i < m; ++i)
  {
    ll x,y;
    cin>>x>>y;
    x--,y--;
    gr[x].pb(y),gr[y].pb(x);
  }
  for (ll i = 0; i < n; ++i)
  {
    if(cum[i]==0){
      dfs(i,i);
    }
  }
  ll sol=0;
  for (int i = 0; i < n; ++i)
  {
    sol+=dp[i];
  }
  cout<<sol<<'\n';
  return 0;
}

Compilation message

count_triplets.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
count_triplets.cpp:6:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
count_triplets.cpp: In function 'void setIO(std::__cxx11::string)':
count_triplets.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(),"r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:29:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(),"w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 653 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 653 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1126 ms 425156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 12408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 12368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 653 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 653 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -