QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93926#5520. Distance ParitiesAsad_BinTL 2ms3444kbC++173.7kb2023-04-04 03:49:172023-04-04 03:49:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-04 03:49:20]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3444kb
  • [2023-04-04 03:49:17]
  • 提交

answer

// . . . Bismillahir Rahmanir Rahim . . .
 
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#ifndef ONLINE_JUDGE
#define dbg_out cout
#define debug(...) dbg_out << "DBG )> "; __f(#__VA_ARGS__, __VA_ARGS__);
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> pr) { out << "{ " << pr.first << ", " << pr.second << " }"; return out; }
template<typename T1> ostream& operator<<(ostream& out, vector<T1> vec) { out << "{ "; for (auto &x: vec) out << x << ", "; out << "}"; return out; }
template<typename T1, size_t size> ostream& operator<<(ostream& out, array<T1, size> arr) { out << "{ "; for (auto &x: arr) out << x << ", "; out << "}"; return out; }
template<typename T1, typename T2> ostream& operator<<(ostream& out, map<T1, T2> mp) { out << "{ ";for (auto &x: mp) out << x.first << ": " << x.second <<  ", "; out << "}"; return out; }
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { while (isspace(name[0])) name++; (isalpha(name[0]) || name[0] == '_') ? dbg_out << name << ": " << arg1 << "\n" : dbg_out << arg1 << "\n"; dbg_out.flush();}
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) { const char *comma = strchr(names + 1, ','); while (isspace(names[0])) names++; (isalpha(names[0]) || names[0] == '_') ? dbg_out.write(names, comma - names) << ": " << arg1 << " | " : dbg_out << arg1 << " | "; __f(comma + 1, args...);}
#else
#define debug(...)
#endif
 
ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;}
ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);}
ll ncr(ll a, ll b){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K; ans /= L;} return ans;}
ll bigmod(ll a,ll b,ll mod){ if(b==0){ return 1;} ll tm=bigmod(a,b/2,mod); tm=(tm*tm)%mod; if(b%2==1) tm=(tm*a)%mod; return tm;}
ll egcd(ll a,ll b,ll &x,ll &y){ if(a==0){ x=0; y=1; return b;} ll x1,y1; ll d=egcd(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; return d;}
ll modpow(ll a,ll p,ll mod) {ll ans=1;while(p){if(p%2)ans=(ans*a)%mod;a=(a*a)%mod;p/=2;} return ans;}
ll inverse_mod(ll n,ll mod) {return modpow(n,mod-2,mod);}


const int N = 500;
vector<int> edge[N+5];
int vis[N+5];

int dfs(int u)
{
	int cnt = 0;
	vis[u] = 1;
	for(auto v : edge[u]){
		if(!vis[v]) cnt += dfs(v);
	}
	
	return cnt + 1;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int t; cin >> t;
	while(t--){
		int n; cin >> n;
		
		string s[n];
		for(int K = 0; K < n; K++) cin >> s[K];
		
		int ara[n+1][n+1];
		for(int K = 1; K <= n; K++) {
			for(int L = 1; L <= n; L++) ara[K][L] = s[K-1][L-1] - '0';
		}
		
		vector<pair<int, int> > v;
		map<pair<int, int>, int> mp;
		for(int L = 1; L <= n; L++){
			for(int K = 1; K <= n; K++){
				for(int M = 1; M <= n; M++){
					if(K == L || M == L) continue;
					
					if((ara[K][L] + ara[L][M])%2 == ara[K][M]){
						if(ara[K][L] && !mp[{K, L}]){
							v.push_back({K, L});
							mp[{K, L}]++;
						}
						if(ara[L][M] && !mp[{L, M}]){
							v.push_back({L, M});
							mp[{L, M}]++;
						}
						if(ara[K][M] && !mp[{K, M}]){
							v.push_back({K, M});
							mp[{K, M}]++;
						}
					}
				}
			}
		}
		
		mp.clear();
		for(auto it:v) mp[{min(it.first, it.second), max(it.first, it.second)}]++;
		v.clear();
		for(auto it:mp) v.push_back(it.first);
		
		for(int K = 1; K <= n; K++) edge[K].clear();
		memset(vis, 0, sizeof vis);
		for(auto it: v){
			edge[it.first].push_back(it.second);
			edge[it.second].push_back(it.first);
		}
		
		int cnt = dfs(1);
		
		if(cnt != n){
			cout << "NO\n";
			continue;
		}
		
		cout << "YES\n";
		cout << (int)v.size() << "\n";
		for(auto it : v) cout << it.first << ' ' << it.second << "\n";
	}
	
	return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

详细

Test #1:

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

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
Time Limit Exceeded

input:

1
500
001001010000101001100000100011101011010001100110010000011000001100000011010001001111001010010101110100000100011000110111100010001000010111111000000101101010011111000010110010111100111110111000010000100100010010001110000100111000001111101011111101111110111110001000111110001011111100110011100100...

output:


result: