Submission #241708

#TimeUsernameProblemLanguageResultExecution timeMemory
241708atoiz철인 이종 경기 (APIO18_duathlon)C++14
100 / 100
87 ms16888 KiB
    #include <stdio.h>
     
    #define N 100007
    #define M 400007
    int n, m, to[M], nx[M], st[N], low[N], vis[N], ts, stk[N], instack[N], *top = &stk[0];
    int bto[N * 4], bnx[N * 4], bst[N * 2], b, bm, bsz[N * 2];
    long long ans = 0;
     
    inline void minimize(int &i, int j) { (i > j ? i = j : 0); }
     
    void build(int u, int p)
    {
    	low[u] = vis[u] = ++ts;
    	instack[*(++top) = u] = 1;
     
    	int i, v, w, c = 0;
    	for (i = st[u]; i; i = nx[i]) if (to[i] != p) {
    		v = to[i];
    		if (!vis[v]) {
    			++c;
    			build(v, u);
    			if (low[v] >= vis[u]) {
    				++b;
    				bool cont = true;
    				while (cont) {
    					instack[w = (*top--)] = 0;
    					cont = (w != v);
    					++bm, bnx[bm] = bst[w], bto[bst[w] = bm] = b;
    					++bm, bnx[bm] = bst[b], bto[bst[b] = bm] = w;
    				}
    				++bm, bnx[bm] = bst[b], bto[bst[b] = bm] = u;
    				++bm, bnx[bm] = bst[u], bto[bst[u] = bm] = b;
    			}
    			minimize(low[u], low[v]);
    		} else if (instack[v]) {
    			minimize(low[u], vis[v]);
    		}
    	}
    }
     
    void solve(int u, int p)
    {
    	int i, v, d = 0;
    	long long x = 0;
     
    	bsz[u] = (u <= n);
    	for (i = bst[u]; i; i = bnx[i]) if (bto[i] != p) {
    		solve(v = bto[i], u), bsz[u] += bsz[v], ++d;
    		x += (long long) bsz[v] * (bsz[v] - 1);
    	}
     
    	if (u > n) {
    		x += (long long) (ts - bsz[u]) * (ts - bsz[u] - 1);
    		ans -= x * d;
    	}
    }
     
    int main()
    {
    	int i, u, v;
    	scanf("%d %d", &n, &m);
    	for (i = 1; i <= m; ++i) {
    		scanf("%d %d", &u, &v);
    		nx[i * 2] = st[u], to[st[u] = i * 2] = v;
    		nx[i * 2 - 1] = st[v], to[st[v] = i * 2 - 1] = u;
    	}
     
    	b = n;
    	for (i = 1; i <= n; ++i) if (!vis[i]) {
    		ts = 0;
    		build(i, 0);
    		ans += (long long) ts * (ts - 1) * (ts - 2);
    		solve(i, 0);
    	}
    	printf("%lld", ans);
    }

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:61:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d %d", &n, &m);
      ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:63:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &u, &v);
       ~~~~~^~~~~~~~~~~~~~~~~
#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...