神秘wa on test 29求条
查看原帖
神秘wa on test 29求条
1236247
Da_Vinci楼主2024/11/21 16:27

错误信息:wrong answer Answer must be equal to the value of shortest path's length: output is 138, should be 137

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pc putchar
template<typename T> inline void fr(T& num){
	num=0;short sign=1;char ch=std::getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')sign=-1;
		ch=std::getchar();
	}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num=num*sign;
}
template<typename T>inline void fw(T x){
	if(x<0)std::putchar('-'),x=-x;
	if(x>9)fw(x/10);
	std::putchar(x%10+'0');
}
const int N=1<<19;
int n,m,dis[N],col[N];
vector<pair<int,int> > g[N];
bitset<N> vis;


void solve(){
	fr(n),fr(m);
	if(n==1)return puts("0\n0"),void();
	memset(col,-1,sizeof col);
	memset(dis,-1,sizeof dis);
	for(int i=1;i<=m;i++){
		int u,v,w;fr(u),fr(v),fr(w);
		g[v].emplace_back(u,w);
	}
	queue<int> q;
	q.emplace(n);
	dis[n]=0;
	while(q.size()){
		int x=q.front();q.pop();
//		cerr<<x<<' '<<dis[x]<<'\n';
		if(x==1)break;
		
		for(auto [y,z]:g[x]){
			
			if(vis[y])continue;
			//cerr<<x<<' '<<y<<' '<<col[y]<<' '<<z<<'\n';
			if(col[y]==-1){
				col[y]=!z;
				continue;
			}
			else if(col[y]==z){
				dis[y]=dis[x]+1,vis[y]=1;
				q.emplace(y);
			}
		}
	}
	fw(dis[1]),pc('\n');
	for(int i=1;i<=n;i++)fw(col[i]==-1?1:col[i]),pc(' ');
	
}
int main(){
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	int Count=1;//fr(Count);
	while(Count--)solve();
}
/*
多测不清空,OI见祖宗。
multitesting without clearing,oier meets the LCA.
十年OI一场空,不开LL见祖宗。
Ten years of OI just AFO,no #define int long long sees the LCA.
似是神犇成才处,实为蒟蒻黄泉路。
It is likely to be the Au medal for the big old,but in fact it is the Si medal for me.
黄题有恨无正解,码力不若小学生。
A yellow problem I can't AC,codeforces is not as NB as EUlar Shai.
今生无奈入OI,来世不做信竞人。
This life I am a Silly Being in oi,next life I won't f**k the sh*t of infomatics.
*/

2024/11/21 16:27
加载中...