Submission #26349

# Submission time Handle Problem Language Result Execution time Memory
26349 2017-06-29T09:48:06 Z dotorya 작은 사이클들 (YDX13_smallcycles) C++14
0 / 1
0 ms 10716 KB
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

vector <int> conn[100050];
int par[100050];
int dep[100050];
int low[100050];
int r[100050];
bool dchk[100050];
int root(int x) {
	return (x == r[x]) ? x : (r[x] = root(r[x]));
}
void DFS1(int n) {
	dchk[n] = true;
	low[n] = dep[n];
	for (auto it : conn[n]) {
		if (par[n] == it) continue;
		if (dchk[it]) {
			r[root(n)] = root(it);
			low[n] = min(low[n], dep[it]);
			continue;
		}
		par[it] = n;
		dep[it] = dep[n] + 1;
		DFS1(it);
		if (low[it] <= dep[n]) r[root(it)] = root(n);
	}
}

vector <int> gconn[100050];
vector <int> glist[100050];
int main() {
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	while (M--) {
		scanf("%d %d", &i, &j);
		conn[i].push_back(j);
		conn[j].push_back(i);
	}
	for (i = 1; i <= N; i++) r[i] = i;
	for (i = 1; i <= N; i++) if (!dchk[i]) DFS1(i);
	for (i = 1; i <= N; i++) glist[root(i)].push_back(i);
	for (i = 1; i <= N; i++) {
		for (auto it : conn[i]) if (root(it) != root(i) && glist[root(it)].size() == 1 && glist[root(i)].size() == 1) gconn[root(i)].push_back(root(it));
	}

	int ans = 0;
	for (i = 1; i <= N; i++) dchk[i] = false;
	for (i = 1; i <= N; i++) {
		if (dchk[i]) continue;
		vector <int> Vu;
		Vu.push_back(i);
		dchk[i] = true;
		for (j = 0; j < Vu.size(); j++) {
			for (auto it : gconn[Vu[j]]) {
				if (dchk[it]) continue;
				Vu.push_back(it);
				dchk[it] = true;
			}
		}
		ans += (int)(Vu.size() - 1) / 2;
	}
	return !printf("%d\n", ans);
}

Compilation message

E.cpp:23:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)  
 ^
E.cpp:24:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:336777216")  
 ^
E.cpp: In function 'int main()':
E.cpp:98:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (j = 0; j < Vu.size(); j++) {
                 ^
E.cpp:78:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
                        ^
E.cpp:80:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &i, &j);
                         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 10716 KB Output is correct
2 Correct 0 ms 10716 KB Output is correct
3 Incorrect 0 ms 10716 KB Output isn't correct
4 Halted 0 ms 0 KB -