QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604944#8760. 不等式xing4c#WA 5ms20960kbC++141.7kb2024-10-02 14:42:532024-10-02 14:42:54

Judging History

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

  • [2024-10-02 14:42:54]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:20960kb
  • [2024-10-02 14:42:53]
  • 提交

answer

#include <bits/stdc++.h>
#define NOSYNC ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int N = 200005;

// -------------- Templates Above -------------------------

int a[N]; int n, m;
vector<int> G[N]; vector<int> g[N];
int in[N]; int vis[N]; int d[N];
vector<int> ano[N]; int vq[N];

signed main() {
	NOSYNC;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++) {
		int x, y, z;
		cin >> x >> y >> z;	
		G[x].push_back(y);
		G[x].push_back(z);
		++ d[y]; ++ d[z];
		ano[y].push_back(z);
		ano[z].push_back(y);
		g[y].push_back(x);
		g[z].push_back(x);
		in[x] += 2;
	}
	
	queue<int> q;
	for(int i = 1; i <= n; i ++) {
		if(!d[i]) {
			q.push(i);
		}
	}
	
	while(!q.empty()) {
		int u = q.front(); q.pop();
		vis[u] = 1;
		for(int v : G[u]) {
			-- d[v];
			if(!d[v]) {
				q.push(v);
			}
		}
	}
	for(int i = 1; i <= n; i ++) {
		if(!vis[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	
	for(int i = 1; i <= n; i ++) vis[i] = 0;
	
	queue<int> q1;
	
	for(int i = 1; i <= n; i ++) {
		if(!in[i]) {
			q1.push(i);
			a[i] = 1;
		}
	}
	while(!q1.empty()) {
		int u = q1.front(); q1.pop();
		vq[u] = 1;
		for(int v : g[u]) {
			for(int w : ano[u]) {
				if(!vq[w]) continue;
				// cout << "u: " << u << " v: " << v << " w: " << w << endl;
				a[v] = max(a[v], a[u] + a[w]);
			}
			-- in[v];
			if(!in[v]) {
				q1.push(v);
			}
		}
	}
	
	
	
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		ans += a[i];
	}
	if(ans > 1e9 ) {
		cout << -1 << endl;
	}
	cout << ans << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 19988kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 4ms
memory: 20760kb

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 3ms
memory: 20308kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

score: 0
Accepted
time: 3ms
memory: 20960kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 4ms
memory: 20292kb

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

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

input:

5 2
1 2 3
2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #11:

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

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

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

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

score: 0
Accepted
time: 3ms
memory: 19988kb

input:

10 2
1 2 3
2 3 4

output:

13

result:

ok 1 number(s): "13"

Test #14:

score: 0
Accepted
time: 5ms
memory: 20064kb

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

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

input:

10 3
1 2 3
1 8 8
2 3 3

output:

13

result:

ok 1 number(s): "13"

Test #16:

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

input:

20 1
1 2 2

output:

21

result:

ok 1 number(s): "21"

Test #17:

score: 0
Accepted
time: 3ms
memory: 20808kb

input:

20 2
1 2 3
2 3 3

output:

23

result:

ok 1 number(s): "23"

Test #18:

score: 0
Accepted
time: 2ms
memory: 20024kb

input:

20 3
7 14 6
1 2 3
4 7 20

output:

24

result:

ok 1 number(s): "24"

Test #19:

score: 0
Accepted
time: 2ms
memory: 20356kb

input:

20 4
1 2 2
6 10 6
2 3 3
3 4 5

output:

-1

result:

ok 1 number(s): "-1"

Test #20:

score: 0
Accepted
time: 3ms
memory: 20056kb

input:

20 5
1 17 3
1 2 3
2 3 4
3 4 5
8 13 16

output:

28

result:

ok 1 number(s): "28"

Test #21:

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

input:

200 9
1 2 2
2 3 3
3 4 5
91 112 195
126 145 82
4 5 5
53 2 15
5 6 6
6 7 7

output:

341

result:

wrong answer 1st numbers differ - expected: '318', found: '341'