QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#289137#7860. Graph of Maximum Degree 3ucup-team266#WA 2ms6188kbC++143.7kb2023-12-23 15:40:302023-12-23 15:40:33

Judging History

你现在查看的是最新测评结果

  • [2023-12-23 15:40:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6188kb
  • [2023-12-23 15:40:30]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const int Mod = 998244353;
int sign(int a){ return (a&1) ? (Mod-1) : 1; }
void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, ll p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 10010;
int fact[fN], invfact[fN], inv[fN];
void initfact(int n){
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
	invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
	for(int i = 1; i <= n; ++i) inv[i] = mul(invfact[i], fact[i-1]);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
void chmax(int &a, int b){ (b>a) ? (a=b) : 0; }
void chmin(int &a, int b){ (b<a) ? (a=b) : 0; }

int n, m;
vector<pii> g[100100];

int dsu[2][4]; int getdsu(int id, int u){ return dsu[id][u] = dsu[id][u] == u ? u : getdsu(id, dsu[id][u]); }

bool done[100100];
mt19937 rnd(114514);
int id[100100];
int main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> m;
	rep(i, m){
		int u, v, w;
		u=1+rnd()%n,v=1+rnd()%n,w=rnd()%2;
		while(v==u)  v=1+rnd()%n;
//		cin >> u >> v >> w;
		--u, --v;
		g[u].push_back(make_pair(v, w));
		g[v].push_back(make_pair(u, w));
	}
//	for(int i=1;i<=n;i++) assert(g[i].size()<=3);
	int ans = n;

	int s2 = 0;
	rep(i, n){
		bool has = 0;
		rep(j, (int)g[i].size()){
			rep(k, j){
				if(g[i][j].first == g[i][k].first && g[i][j].second != g[i][k].second)
					++s2, has = 1;
				if(has) break;
			}
			if(has) break;
		}
	}
	s2 /= 2;
	ans += s2;

	int s3 = 0;
	rep(i, n){
		if((int)g[i].size() < 3) continue;
		rep(j, (int)g[i].size()) rep(k, j){
			if(g[i][j].first == g[i][k].first && g[i][j].second != g[i][k].second){
				int u = g[i][j].first, v = g[i][(3 - j - k)].first, vw = g[i][(3 - j - k)].second;
				bool ok = 0;
				rep(l, (int)g[u].size()) ok |= (g[u][l].first == v && g[u][l].second != vw);
				s3 += ok;
			}
		}
	}
	s3 /= 2;
	ans += s3;

	
	memset(id, -1, sizeof(id));
	vi v,nv; 
	int s4 = 0;
//	map<pii,int> Mp[2];
	rep(i, n){
		if(done[i] || (int)g[i].size() < 3) continue;
		rep(j, 4) dsu[0][j] = dsu[1][j] = j;
		v.clear(),v.push_back(i);
//		cout<<v.size()<<"\n";
		rep(j, 3) v.push_back(g[i][j].first);
		sort(v.begin(), v.end());
		v.resize(unique(v.begin(), v.end()) - v.begin());
		nv=v;
		int cur=v.size();
		for(int C=0;C<cur;C++)
			for(int B=0;B<(int)g[v[C]].size();B++)
				nv.push_back(g[v[C]][B].first);
		v=nv;
		sort(v.begin(), v.end());
		v.resize(unique(v.begin(), v.end()) - v.begin());
		if(v.size()!=4) continue;
		rep(j, 4) done[v[j]] = 1, id[v[j]] = j;
		bool ok = 1;
		rep(j, 4) rep(k, (int)g[v[j]].size()){
			int t = g[v[j]][k].first, w = g[v[j]][k].second;
			if(id[t] < 0) ok = 0;
			dsu[w][getdsu(w, id[t])] = getdsu(w, j);
		}
		rep(j, 4) done[v[j]] = 1, id[v[j]] = -1;
		rep(j, 4) ok &= getdsu(0, j) == getdsu(0, 0);
		rep(j, 4) ok &= getdsu(1, j) == getdsu(1, 0);
		s4 += ok;
	}
	ans += s4;

	cout << ans << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 6188kb

input:

3 4
1 2 0
1 3 1
2 3 0
2 3 1

output:

3

result:

wrong answer 1st numbers differ - expected: '5', found: '3'