QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#548065#8760. 不等式xfs001WA 20ms99452kbC++141.1kb2024-09-05 15:06:482024-09-05 15:06:49

Judging History

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

  • [2024-09-05 15:06:49]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:99452kb
  • [2024-09-05 15:06:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>g[2020000];
vector<pair<int,int>>v[2020000];
int r[2020000],a[2020000];
void dfs(int u,int f){
	if(a[u])return;
	int x=0;
	for(auto v:g[u]){
		if(v==f)continue;
		dfs(v,u);
		// x+=a[v];
	}
	for(auto it:v[u]){
		x=max(a[it.first]+a[it.second],x);
	}
	a[u]=x;
}
void solve(){
	int n,m,f=1;cin>>n>>m;
	while(m--){
		int x,y,z;cin>>x>>y>>z;
		g[x].push_back(y);
		g[x].push_back(z);
		g[y].push_back(x);
		g[z].push_back(x);
		v[x].push_back({z,y});
		r[x]+=2;
	}	
	queue<int>q;
	vector<int>res;
	for(int i=1;i<=n;i++){
		if(r[i]==0){
			q.push(i);
			a[i]=1;
		}
	}
	while(q.size()){
		int p=q.front();q.pop();
		res.push_back(p);
		for(auto it:g[p]){
			r[it]--;
			if(r[it]==0)
				q.push(it);
		}
	}
	if(res.size()!=n){
		cout<<-1<<'\n';
	}else{
		int ans=0;
		f=res.back();
		// cout<<f;
		dfs(f,-1);
		for(int i=1;i<=n;i++)
			ans+=a[i];
		if(ans>1e9){
			cout<<-1;
		}else
			cout<<ans;
	}
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 12ms
memory: 98260kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 7ms
memory: 98260kb

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 20ms
memory: 98268kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 8ms
memory: 98336kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: 0
Accepted
time: 16ms
memory: 98264kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 16ms
memory: 98564kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

score: 0
Accepted
time: 14ms
memory: 98528kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 12ms
memory: 98360kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 16ms
memory: 98524kb

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 16ms
memory: 98260kb

input:

5 2
1 2 3
2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #11:

score: 0
Accepted
time: 16ms
memory: 99452kb

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

score: 0
Accepted
time: 15ms
memory: 98188kb

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

score: 0
Accepted
time: 8ms
memory: 98556kb

input:

10 2
1 2 3
2 3 4

output:

13

result:

ok 1 number(s): "13"

Test #14:

score: 0
Accepted
time: 7ms
memory: 98188kb

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

score: 0
Accepted
time: 11ms
memory: 98328kb

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: 17ms
memory: 98320kb

input:

20 1
1 2 2

output:

21

result:

ok 1 number(s): "21"

Test #17:

score: 0
Accepted
time: 12ms
memory: 98320kb

input:

20 2
1 2 3
2 3 3

output:

23

result:

ok 1 number(s): "23"

Test #18:

score: -100
Wrong Answer
time: 11ms
memory: 98264kb

input:

20 3
7 14 6
1 2 3
4 7 20

output:

22

result:

wrong answer 1st numbers differ - expected: '24', found: '22'