QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220656#6555. Sets May Be Gooducup-team191#WA 1ms3364kbC++141.8kb2023-10-20 17:04:382023-10-20 17:04:39

Judging History

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

  • [2023-10-20 17:04:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3364kb
  • [2023-10-20 17:04:38]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef pair < int, int > pii;

const int N = 1e3 + 50;
const int MOD = 998244353;

inline int add(int A, int B) {
	if(A + B >= MOD) return A + B - MOD;
	return A + B;
}

inline int sub(int A, int B) {
	if(A - B < 0) return A - B + MOD;
	return A - B;
}

inline int mul(int A, int B) {
	return (long long)A * B % MOD;
}

int n, m, par[N];

vector < pii > edg;
vector < int > v[N];

void dfs(int x) {
	
}

int pr(int x) {
	if(x == par[x]) return x;
	return par[x] = pr(par[x]);
}

void mrg(int x, int y) {
	par[pr(x)] = pr(y);
}

void rebuild(){
	for(int i = 1;i <= n;i++) par[i] = i, v[i].clear();
	for(auto tmp : edg) mrg(tmp.X, tmp.Y), v[tmp.X].PB(tmp.Y), v[tmp.Y].PB(tmp.X);
}

map < int, bool > makni[N];

void ocisti() {
	vector < pii > nw;
	for(auto tmp : edg)
		if(!makni[tmp.X][tmp.Y] && !makni[tmp.Y][tmp.X])
			nw.PB(tmp);
	edg = nw;	
}

bool nadi_put(int x, int target, int lst) {
	if(x == target) return true;
	for(int y : v[x]) {
		if(y != lst) {
			if(nadi_put(y, target, x)) {
				makni[x][y] = true;
				return true;
			}
		}
	}
	return false;
}

int  pot2[N];

int main(){
	scanf("%d%d", &n, &m);
	pot2[0] = 1;
	for(int i = 1;i <= n;i++) par[i] = i, pot2[i] = add(pot2[i - 1], pot2[i - 1]);
	for(int i = 0;i < m;i++) {
		int x, y; scanf("%d%d", &x, &y);
		if(pr(x) == pr(y)) {
			nadi_put(x, y, x);
			ocisti();
			rebuild();
		} else {
			edg.PB({x, y});
			mrg(x, y);
			v[x].PB(y), v[y].PB(x);
		}
	}
	if((int)edg.size() == 0) {
		if(m > 0) printf("%d\n", pot2[n - 1]);
		else printf("%d\n", pot2[n]);
	} else {
		printf("%d\n", mul(3, pot2[n - 2]));
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3188kb

input:

5 5
1 2
2 3
3 4
4 5
1 5

output:

16

result:

ok 1 number(s): "16"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3116kb

input:

3 0

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3236kb

input:

2 1
1 2

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3364kb

input:

4 6
1 2
1 3
1 4
2 3
2 4
3 4

output:

12

result:

wrong answer 1st numbers differ - expected: '6', found: '12'