Submission #371316


Source Code Expand

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int n;
int dig[100100];
const int SIZE = 100100;
vector<int> g[100100];
struct UnionFind
{
	int par[SIZE],rank[SIZE];
	void init(int n)
	{
		int i;
		for(i=0;i<n;i++)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x)
	{
		if(par[x] == x)
		{
			return x;
		}
		else
		{
			return par[x] = find(par[x]);
		}
	}
	void unite(int x,int y)
	{
		x = find(x);
		y = find(y);
		if(rank[x] < rank[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if(rank[x] == rank[y])rank[x]++;
		}	
	}
	bool same(int x,int y)
	{
		return find(x) == find(y);
	}
}uf;
int depth[100100];
void dfs(int v,int p,int d)
{
	depth[v]=d;
	for(int i=0;i<g[v].size();i++)
	{
		if(g[v][i]==p)continue;
		dfs(g[v][i],v,d+1);
	}
}
int u,v;
int main()
{
	cin >> n;
	uf.init(n);
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		dig[a]++;
		dig[b]++;
		if(uf.same(a,b))
		{
			u=a;v=b;
		}
		else
		{
			uf.unite(a,b);
			g[a].pb(b);
			g[b].pb(a);
		}
	}
	int mdig=INF;
	for(int i=0;i<n;i++)mdig = min(mdig,dig[i]);
	dfs(0,-1,0);
	if((depth[u]%2)==(depth[v]%2))printf("%d %d\n",mdig,n-1);
	else printf("%d %d\n",mdig,n);
	return 0;
}

Submission Info

Submission Time
Task C - 最小カットと最大カット
User okura
Language C++ (GCC 4.9.2)
Score 100
Code Size 2048 Byte
Status AC
Exec Time 188 ms
Memory 11816 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 29
Set Name Test Cases
All scrambled_00.txt, scrambled_01.txt, scrambled_02.txt, scrambled_03.txt, scrambled_04.txt, scrambled_05.txt, scrambled_06.txt, scrambled_07.txt, scrambled_08.txt, scrambled_09.txt, scrambled_10.txt, scrambled_11.txt, scrambled_12.txt, scrambled_13.txt, scrambled_14.txt, scrambled_15.txt, scrambled_16.txt, scrambled_17.txt, scrambled_18.txt, scrambled_19.txt, scrambled_20.txt, scrambled_21.txt, scrambled_22.txt, scrambled_23.txt, scrambled_24.txt, scrambled_25.txt, scrambled_26.txt, scrambled_27.txt, scrambled_28.txt
Case Name Status Exec Time Memory
scrambled_00.txt AC 28 ms 3096 KB
scrambled_01.txt AC 27 ms 3100 KB
scrambled_02.txt AC 26 ms 3228 KB
scrambled_03.txt AC 181 ms 10784 KB
scrambled_04.txt AC 188 ms 11816 KB
scrambled_05.txt AC 122 ms 8804 KB
scrambled_06.txt AC 86 ms 6172 KB
scrambled_07.txt AC 174 ms 9632 KB
scrambled_08.txt AC 73 ms 5276 KB
scrambled_09.txt AC 89 ms 6236 KB
scrambled_10.txt AC 160 ms 8224 KB
scrambled_11.txt AC 79 ms 5040 KB
scrambled_12.txt AC 130 ms 7204 KB
scrambled_13.txt AC 127 ms 6936 KB
scrambled_14.txt AC 174 ms 7716 KB
scrambled_15.txt AC 133 ms 6432 KB
scrambled_16.txt AC 79 ms 4820 KB
scrambled_17.txt AC 80 ms 4904 KB
scrambled_18.txt AC 177 ms 7840 KB
scrambled_19.txt AC 39 ms 3492 KB
scrambled_20.txt AC 117 ms 6048 KB
scrambled_21.txt AC 79 ms 4896 KB
scrambled_22.txt AC 126 ms 6428 KB
scrambled_23.txt AC 85 ms 5148 KB
scrambled_24.txt AC 80 ms 4900 KB
scrambled_25.txt AC 99 ms 5532 KB
scrambled_26.txt AC 82 ms 5032 KB
scrambled_27.txt AC 115 ms 6048 KB
scrambled_28.txt AC 108 ms 5792 KB