답안 #710293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710293 2023-03-15T06:44:48 Z lam 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 10;
int n,m;
vector <int> adj[maxn];
int dp[maxn],dp2[maxn],s[maxn];
bool dau[maxn];
vector <int> root;
int ans = 0LL;
void dfs(int x, int p)
{
    dau[x] = 1;
    dp[x] = 0;
    for (int i:adj[x])
        if (i!=p)
    {
        dfs(i,x);
        dp[x] += dp[i]+1;
        int temp = (dp[i]+1);
        int temp2 = (n-temp-1);
        if (temp>0&&temp2>0)
        ans += temp*temp2;
    }
}

void dfs2(int x, int p, int val)
{
    dp2[x] = val;
    int temp = n-val-1;
    if (temp>0&&val>0)
    ans+=val*temp;
    val++;
    vector <int> pre,suf;
    for (int i:adj[x])
        if (i!=p)
    {
        pre.push_back(dp[i]+1);
        suf.push_back(dp[i]+1);
    }
    for (int i=1; i<pre.size(); i++) pre[i]+=pre[i-1];
    for (int i=suf.size()-2; i>=0; i--) suf[i]+=suf[i+1];
    int cnt=0;
    for (int i:adj[x])
        if (i!=p)
    {
        int val2 = val;
        if (cnt>0) val2 += pre[cnt-1];
        if (cnt<(int)suf.size()-1) val2+=suf[cnt+1];
        cnt++;
        dfs2(i,x,val2);
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
//    freopen("dualthon.inp","r",stdin);
//    freopen("dualthon.out","w",stdout);
    cin>>n>>m;
    for (int i=1; i<=m; i++)
    {
        int u,v; cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i=1; i<=n; i++) if (!dau[i]) dfs(i,i), root.push_back(i);
    for (int i:root) dfs2(i,i,0);
    cout<<ans<<'\n';
}

Compilation message

count_triplets.cpp: In function 'void dfs2(long long int, long long int, long long int)':
count_triplets.cpp:41:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i=1; i<pre.size(); i++) pre[i]+=pre[i-1];
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 474 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 474 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 508224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Incorrect 2 ms 2644 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 8032 KB Output is correct
2 Correct 62 ms 8080 KB Output is correct
3 Correct 92 ms 8000 KB Output is correct
4 Correct 67 ms 8048 KB Output is correct
5 Correct 83 ms 8052 KB Output is correct
6 Correct 105 ms 20144 KB Output is correct
7 Correct 97 ms 16396 KB Output is correct
8 Correct 109 ms 14244 KB Output is correct
9 Correct 88 ms 12204 KB Output is correct
10 Incorrect 91 ms 8044 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Runtime error 578 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 8068 KB Output is correct
2 Correct 93 ms 7880 KB Output is correct
3 Runtime error 882 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 474 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 474 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -