QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#668408#5520. Distance ParitiesxhytomWA 91ms7132kbC++233.3kb2024-10-23 14:17:592024-10-23 14:18:01

Judging History

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

  • [2024-10-23 14:18:01]
  • 评测
  • 测评结果:WA
  • 用时:91ms
  • 内存:7132kb
  • [2024-10-23 14:17:59]
  • 提交

answer

/*
 
_/      _/    _/      _/    _/      _/   _/_/_/_/_/     _/_/       _/      _/ 
 _/    _/     _/      _/     _/    _/        _/       _/    _/     _/      _/            
  _/  _/      _/      _/      _/  _/         _/      _/      _/    _/_/  _/_/         
   _/_/       _/_/_/_/_/        _/           _/      _/      _/    _/  _/  _/          
  _/  _/      _/      _/        _/           _/      _/      _/    _/      _/          
 _/    _/     _/      _/        _/           _/       _/    _/     _/      _/          
_/      _/    _/      _/        _/           _/         _/_/       _/      _/       
 
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using i64 = long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define multi int _;cin>>_;while(_--)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define int long long
#define pb push_back
#define eb emplace_back
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
mt19937_64 mrand(chrono::steady_clock().now().time_since_epoch().count());
int rnd(int l,int r){ return mrand() % (r - l + 1) + l;}
void test() {cerr << "\n";}
template<typename T, typename... Args> 
void test(T x, Args... args) {cerr << x << " ";test(args...);}
const ll MOD = 998244353;
// const ll MOD = 1e9+7;
ll ksm(ll x,ll y){ll ans=1;x%=MOD;while(y){if(y&1)ans=ans*x%MOD;x=x*x%MOD,y/=2;}return ans;}

const int P1 = 972152273, base1 = 809;
const int P2 = 905563261, base2 = 919;
const ll N = 200005;
//head

struct DSU {
    std::vector<int> f, siz;
    DSU(int n) : f(n), siz(n, 1) { std::iota(f.begin(), f.end(), 0); }
    int leader(int x) {
        while (x != f[x]) x = f[x] = f[f[x]];
        return x;
    }
    bool same(int x, int y) { return leader(x) == leader(y); }
    bool merge(int x, int y) {
        x = leader(x);
        y = leader(y);
        if (x == y) return false;
        siz[x] += siz[y];
        f[y] = x;
        return true;
    }
    int size(int x) { return siz[leader(x)]; }
};

void solve(int testcase) {
	int n;
	std::cin >> n;
	std::vector<std::vector<int>> a(n + 2, std::vector<int> (n + 2));
	
	DSU dsu(n + 1);
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		std::string s;
		std::cin >> s;
		for (int j = 1; j <= n; j++) {
			a[i][j] = s[j - 1] - '0';
			if (a[i][j] == 1) {
				cnt += dsu.merge(i, j);
			}
		}
	}
	
	auto f = a;
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				f[i][j] = std::min(f[i][j], f[i][k] + f[k][j]);
			}
		}
	}
	if (a != f) {
		std::cout << "NO\n";
		return;
	}
	
	if (cnt + 1 == n) {
		std::cout << "YES\n";
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				ans += a[i][j];
			}
		}
		std::cout << ans << "\n";
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (a[i][j]) {
					std::cout << i << " " << j << "\n";
				}
			}
		}
	} else {
		std::cout << "NO\n";
	}
	
}

signed main()
{  
#ifdef localfreopen
    // freopen("1.in","r",stdin);
#endif
    fastio
    std::cout << std::fixed << std::setprecision(10);
    int t;
    cin >> t;
    for(int i = 1 ; i <= t ; i++ )
    {
        solve(i);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

3
3
011
101
110
4
0100
1000
0001
0010
5
01010
10101
01010
10101
01010

output:

YES
3
1 2
1 3
2 3
NO
YES
6
1 2
1 4
2 3
2 5
3 4
4 5

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 91ms
memory: 7132kb

input:

1
500
001001010000101001100000100011101011010001100110010000011000001100000011010001001111001010010101110100000100011000110111100010001000010111111000000101101010011111000010110010111100111110111000010000100100010010001110000100111000001111101011111101111110111110001000111110001011111100110011100100...

output:

NO

result:

wrong answer Jury found the answer but participant didn't (test case 1)